C++ 的 AIX xlC 交叉编译/链接找不到 C 符号

发布于 2024-08-29 09:20:54 字数 699 浏览 1 评论 0 原文

我正在尝试使用 xlc/xlC 编译器在 AIX 上进行交叉编译。

当代码在另一台机器上使用默认设置时,可以成功编译。代码实际上通过交叉编译成功编译,但问题出在链接器上。这是将对象链接在一起的命令:

$(CHILD_OS)/usr/vacpp/bin/xlC -q32 -qnolib -brtl -o $(EXECUTABLE) $(OBJECT_FILES)   
-L$(CHILD_OS)/usr/lib  
-L$(CHILD_OS)/usr/vacpp/lib/profiled  
-L$(CHILD_OS)/usr/vacpp/lib  
-L$(CHILD_OS)/usr/vac/lib  
-L$(CHILD_OS)/usr/lib  
-lc -lC -lnsl -lpthread  
-F$(CHILD_OS)$(CUSTOM_CONFIG_FILE_LOCATION)

当我尝试链接代码时,我得到几个未定义的符号: .setsockopt(int,int,int,const void*,unsigned long), .socket(int,int,int), .connect(int,const sockaddr*,unsigned long) 等。

我发现缺少的符号是来自标准 C 库 libc.a。当我用 nm 查找正在拾取的 libc.a 的符号时,这些符号确实存在。我猜测 C++ 可能存在无法读取 C 对象的问题,但我确实是在黑暗中拍摄。

I am attempting to cross-compile on AIX with the xlc/xlC compilers.

The code compiles successfully when it uses the default settings on another machine. The code actually successfully compiles with the cross-compilation, but the problem comes from the linker. This is the command which links the objects together:

$(CHILD_OS)/usr/vacpp/bin/xlC -q32 -qnolib -brtl -o $(EXECUTABLE) $(OBJECT_FILES)   
-L$(CHILD_OS)/usr/lib  
-L$(CHILD_OS)/usr/vacpp/lib/profiled  
-L$(CHILD_OS)/usr/vacpp/lib  
-L$(CHILD_OS)/usr/vac/lib  
-L$(CHILD_OS)/usr/lib  
-lc -lC -lnsl -lpthread  
-F$(CHILD_OS)$(CUSTOM_CONFIG_FILE_LOCATION)

When I attempt to link the code, I get several Undefined symbols:
.setsockopt(int,int,int,const void*,unsigned long), .socket(int,int,int), .connect(int,const sockaddr*,unsigned long), etc.

I have discovered that the symbols missing are from the standard c library, libc.a. When I looked up the symbols with nm for the libc.a that is being picked up, the symbols do indeed exist. I am guessing that there might be a problem with the C++ being unable to read the C objects, but I am truly shooting in the dark.

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

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

发布评论

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

评论(2

就此别过 2024-09-05 09:20:54

听起来这可能是一个 C++ 名称修改问题。

在目标文件上运行 nm 以找出它们正在寻找的符号。然后将确切的名称与库进行比较。

然后检查编译命令,以确保包含正确版本的头文件 - 也许它错误地包含了父操作系统的副本?

Sound like it might be a C++ name mangling problem.

Run nm on the object files to find out the symbols that they are looking for. Then compare the exact names against the libraries.

Then check the compilation commands, to ensure that the right version of the header files is being included - maybe it's including the parent OS's copy by mistake?

深居我梦 2024-09-05 09:20:54

我最终能够解决这个问题。看起来我正在使用 C++ 编译器来处理 .c 文件。对 C 文件使用 xlc 编译器而不是 xlC 编译器解决了此问题。

I was eventually able to get around this. It looks like I was using the C++ compiler for .c files. Using the xlc compiler instead of the xlC compiler for C files fixed this problem.

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