报错
server3.c: In function ‘main’:
server3.c:26:63: warning: implicit declaration of function ‘getpid’ [-Wimplicit-function-declaration]
26 | printf("Server pid = %d is ready (msgqid = %d)...\n", getpid(), msgqid);
| ^~~~~~
server3.c:73:60: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
73 | printf("Server exit requested by client pid = %d\n", msg.mtype);
| ~^ ~~~~~~~~~
| | |
| int long int
| %ld
/usr/bin/ld: /tmp/cc0JqXjt.o: in function `main':
server3.c:(.text+0x22c): undefined reference to `pow'
编译运行一切正常,如果pow函数其中一个参数是变量的话就会报异常。所以引用包的时候一定要在编译的时候加-lm信息。
gcc server3.c -o server -lm
即可正常运行