Solaris 下 Sun Studio 10 中的链接错误

发布于 2024-09-26 14:39:39 字数 485 浏览 14 评论 0原文

我写了一个这样的测试程序:

#include <sys/socket.h>
int main( void ) {
    int  sock = socket(AF_INET, SOCK_DGRAM, 0);
    return 0;
}

并尝试编译它:

$ /tool/sunstudio/bin/cc test.c
Undefined                       first referenced
 symbol                             in file
socket                              test.o
ld: fatal: Symbol referencing errors. No output written to a.out

输出是“符号​​套接字未被引用”。

请给我指示,以便我解决这个问题。

I wrote a test program like this:

#include <sys/socket.h>
int main( void ) {
    int  sock = socket(AF_INET, SOCK_DGRAM, 0);
    return 0;
}

And tried to compile it:

$ /tool/sunstudio/bin/cc test.c
Undefined                       first referenced
 symbol                             in file
socket                              test.o
ld: fatal: Symbol referencing errors. No output written to a.out

The output is "symbol socket is not referenced".

Kindly give me the direction so that I can resolve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

同展鸳鸯锦 2024-10-03 14:39:39

这是问题所在。

我编写了一个这样的测试程序:

#include <sys/socket.h>
int main( void ) {
    int  sock = socket(AF_INET, SOCK_DGRAM, 0);
    return 0;
}

并尝试对其进行编译(这是真正有帮助的输出,您必须记住,现代编译器确实尽力帮助您解决任何问题):

$ /tool/sunstudio/bin/cc test.c
Undefined                       first referenced
 symbol                             in file
socket                              test.o
ld: fatal: Symbol referencing errors. No output written to a.out

现在,从输出中我们可以看到未引用符号socket。因此,如果您输入 man socket,您将从手册页中获得以下内容:

SYNOPSIS
     cc [ flag ... ] file ... -lsocket  -lnsl  [ library ... ]

-l 标志表示要使用此函数,您还需要链接指定的库。在这种情况下,系统会告诉您将 -lsocket -lnsl 添加到 cc 命令行,如下所示:

$ /tool/sunstudio/bin/cc test.c -lsocket -lnsl

Here's the question.

I wrote a test program like this:

#include <sys/socket.h>
int main( void ) {
    int  sock = socket(AF_INET, SOCK_DGRAM, 0);
    return 0;
}

And tried to compile it so (this is the output that really helps, you have to remember that modern compilers really try their best to help you fix any problems):

$ /tool/sunstudio/bin/cc test.c
Undefined                       first referenced
 symbol                             in file
socket                              test.o
ld: fatal: Symbol referencing errors. No output written to a.out

Now, from the output we can see that the symbol socket is not referenced. So if you type man socket you will get the following from the man page:

SYNOPSIS
     cc [ flag ... ] file ... -lsocket  -lnsl  [ library ... ]

The -l flag indicates that to use this function you need to also link the named library. In this case you are being told to add -lsocket -lnsl to the cc command line as follows:

$ /tool/sunstudio/bin/cc test.c -lsocket -lnsl
心房的律动 2024-10-03 14:39:39

您必须在命令行中链接到套接字库:

-lsocket 

you have to link in the socket library, in the command line:

-lsocket 
Smile简单爱 2024-10-03 14:39:39

您需要至少添加 -lsocket 到您的链接步骤,即针对 libsocket.so 的链接。不过,我不知道如何在 SunStudio UI 中执行此操作 - 它的项目是否基于 makefile?

手册页通常是查找所需库的好地方;在本例中,套接字手册页 还推荐 -lnsl (请参阅概要),因此可能也需要它,但我不记得它是必要的。

You need to add at least -lsocket to your link-step, i.e. link against libsocket.so. I don't know how to do that in the SunStudio UI, though - are its projects makefile based?

The man page is usually a good place to look for required libraries; in this case the man page for socket also recommends -lnsl (see the synopsis) so that might be required too but I don't remember it being necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文