然后: gcc -std=gnu99 -Wall -c mysocket.c #没问题。 gcc -std=gnu99 -Wall -c ftpserver.c #没问题 gcc -std=gnu99 -Wall -o server mysocket.o ftpserver.o #问题出现了。 报错如下: mysocket.c:(.text+0x37): undefined reference to `print_error_location' mysocket.c:(.text+0xaf): undefined reference to `print_error_location' ftpserver.o: In function `main': ftpserver.c:(.text+0x2f): undefined reference to `print_error_location' ftpserver.c:(.text+0x69): undefined reference to `print_error_location' ftpserver.c:(.text+0xbf): undefined reference to `print_error_location' collect2: ld returned 1 exit status 怎么说我没定义呢?然后,我不这么分开编译了。直接gcc -std=gnu99 -Wall -o server mysocket.c ftpserver.c 还是同样的问题啊。
我在不加-std=gnu99了 gcc -Wall -o server mysocket.c ftpserver.c /tmp/ccKxv8xf.o: In function `print_error_location': ftpserver.c:(.text+0x0): multiple definition of `print_error_location' /tmp/ccoJSGDi.o:mysocket.c:(.text+0x0): first defined here collect2: ld returned 1 exit status 这次是说我重复定义了。
好吧。我在换成c99 gcc -std=c99 -Wall -o server mysocket.c ftpserver.c ftpserver.c: In function ‘main’: ftpserver.c:7:2: warning: implicit declaration of function ‘inet_aton’ [-Wimplicit-function-declaration] /tmp/cc7ZG9r2.o: In function `listen_socket': mysocket.c:(.text+0x37): undefined reference to `print_error_location' mysocket.c:(.text+0xa4): undefined reference to `print_error_location' /tmp/ccjQRw2R.o: In function `main': ftpserver.c:(.text+0x2f): undefined reference to `print_error_location' ftpserver.c:(.text+0x69): undefined reference to `print_error_location' ftpserver.c:(.text+0xb5): undefined reference to `print_error_location' collect2: ld returned 1 exit status 还是说我没定义。