在 OpenSolaris 2008.11 上使用 gcc 编译时出现无法解析的符号
当编译使用套接字的简单 Netbeans C 项目时,我得到以下输出。 我想问题是 gcc 没有正确链接 sockets.h 库。 需要一个万无一失的方法来解决这个问题。
Running "/usr/bin/make -f Makefile CONF=Debug clean" in /export/home/manu/Escritorio/TP-entrega 2/Application_1
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf
rm -f -r build/Debug
rm -f dist/Debug/GNU-Solaris-x86/application_1
Clean successful. Exit value 0.
Running "/usr/bin/make -f Makefile CONF=Debug" in /export/home/manu/Escritorio/TP-entrega 2/Application_1
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Solaris-x86/application_1
mkdir -p build/Debug/GNU-Solaris-x86
rm -f build/Debug/GNU-Solaris-x86/tp2.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-Solaris-x86/tp2.o.d -o build/Debug/GNU-Solaris-x86/tp2.o tp2.c
mkdir -p dist/Debug/GNU-Solaris-x86
gcc -o dist/Debug/GNU-Solaris-x86/application_1 build/Debug/GNU-Solaris-x86/tp2.o
Undefined first referenced
symbol in file
bind build/Debug/GNU-Solaris-x86/tp2.o
recv build/Debug/GNU-Solaris-x86/tp2.o
send build/Debug/GNU-Solaris-x86/tp2.o
accept build/Debug/GNU-Solaris-x86/tp2.o
listen build/Debug/GNU-Solaris-x86/tp2.o
socket build/Debug/GNU-Solaris-x86/tp2.o
ld: fatal: Symbol referencing errors. No output written to dist/Debug/GNU-Solaris-x86/application_1
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `dist/Debug/GNU-Solaris-x86/application_1'
Current working directory /export/home/manu/Escritorio/TP-entrega 2/Application_1
*** Error code 1
make: Fatal error: Command failed for target `.build-conf'
Current working directory /export/home/manu/Escritorio/TP-entrega 2/Application_1
*** Error code 1
make: Fatal error: Command failed for target `.build-impl'
Build failed. Exit value 1.
When compiling a simple Netbeans C project that uses sockets I get the following output.
I suppose the problem is that gcc is not properly linking sockets.h library.
Need a foolproof method to solve this.
Running "/usr/bin/make -f Makefile CONF=Debug clean" in /export/home/manu/Escritorio/TP-entrega 2/Application_1
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf
rm -f -r build/Debug
rm -f dist/Debug/GNU-Solaris-x86/application_1
Clean successful. Exit value 0.
Running "/usr/bin/make -f Makefile CONF=Debug" in /export/home/manu/Escritorio/TP-entrega 2/Application_1
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Solaris-x86/application_1
mkdir -p build/Debug/GNU-Solaris-x86
rm -f build/Debug/GNU-Solaris-x86/tp2.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-Solaris-x86/tp2.o.d -o build/Debug/GNU-Solaris-x86/tp2.o tp2.c
mkdir -p dist/Debug/GNU-Solaris-x86
gcc -o dist/Debug/GNU-Solaris-x86/application_1 build/Debug/GNU-Solaris-x86/tp2.o
Undefined first referenced
symbol in file
bind build/Debug/GNU-Solaris-x86/tp2.o
recv build/Debug/GNU-Solaris-x86/tp2.o
send build/Debug/GNU-Solaris-x86/tp2.o
accept build/Debug/GNU-Solaris-x86/tp2.o
listen build/Debug/GNU-Solaris-x86/tp2.o
socket build/Debug/GNU-Solaris-x86/tp2.o
ld: fatal: Symbol referencing errors. No output written to dist/Debug/GNU-Solaris-x86/application_1
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `dist/Debug/GNU-Solaris-x86/application_1'
Current working directory /export/home/manu/Escritorio/TP-entrega 2/Application_1
*** Error code 1
make: Fatal error: Command failed for target `.build-conf'
Current working directory /export/home/manu/Escritorio/TP-entrega 2/Application_1
*** Error code 1
make: Fatal error: Command failed for target `.build-impl'
Build failed. Exit value 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要适当的
-l
标志。 我正在查找。呃。 添加
-lsocket
。 实际上,您可能也需要-lnsl
。 请参阅此手册页。在 Netbeans 中,这应该位于项目属性中。
You need the appropriate
-l
flag. I'm looking it up.Duh. add
-lsocket
. Actually, you probably need-lnsl
too. See this man page.In Netbeans this should be in the Project Properties.
您需要确保链接器正在链接
socket
和nsl
库。 在命令行中,您可以添加 -lsocket -lnsl 来执行此操作。 我不了解 netbeans,也无法告诉您它到底是如何工作的,但某个地方应该有链接器设置,您可以在其中添加这些库。You need to make sure that the linker is linking the
socket
andnsl
libraries. At the command line you would add-lsocket -lnsl
to do so. I don't know netbeans and can't tell you how it works there exactly, but somewhere there should be linker settings where you can add these libraries.