关于AIX下g++ -static静态链接的问题

gengyonghui 2009-04-14 04:08:16
哪位懂AIX 下g++的兄才帮忙看看,关于-static参数

我在linux下用g++写了个程序,
动态链接如下:
gengyh:~/workspace2/test/Debug # g++ -o test ./src/test.o
gengyh:~/workspace2/test/Debug # ll
total 144
-rw-r--r-- 1 root root 1326 2009-04-14 14:45 makefile
-rw-r--r-- 1 root root 230 2009-04-14 14:45 objects.mk
-rw-r--r-- 1 root root 522 2009-04-14 14:45 sources.mk
drwxr-xr-x 2 root root 4096 2009-04-14 11:27 src
-rwxr-xr-x 1 root root 126481 2009-04-14 15:24 test
静态链接如下:
gengyh:~/workspace2/test/Debug # g++ -static -o test ./src/test.o
gengyh:~/workspace2/test/Debug # ll
total 1340
-rw-r--r-- 1 root root 1326 2009-04-14 14:45 makefile
-rw-r--r-- 1 root root 230 2009-04-14 14:45 objects.mk
-rw-r--r-- 1 root root 522 2009-04-14 14:45 sources.mk
drwxr-xr-x 2 root root 4096 2009-04-14 11:27 src
-rwxr-xr-x 1 root root 1350297 2009-04-14 15:24 test


在AIX下用g++动态链接可以,用静态链接却不行:
# g++ -o test ./src/test.o
# ls -l
total 504
-rw-r--r-- 1 root system 1326 Apr 14 14:45 makefile
-rw-r--r-- 1 root system 230 Apr 14 14:45 objects.mk
-rw-r--r-- 1 root system 522 Apr 14 14:45 sources.mk
drwxr-x--- 2 root system 256 Apr 14 14:45 src
-rwxr-xr-x 1 root system 243383 Apr 14 15:25 test

# g++ -static -o test ./src/test.o
ld: 0711-317 ERROR: Undefined symbol: encrypted_pw_passlen
ld: 0711-317 ERROR: Undefined symbol: max_history_size
ld: 0711-317 ERROR: Undefined symbol: crypt_r
ld: 0711-317 ERROR: Undefined symbol: getpass_auto
ld: 0711-317 ERROR: Undefined symbol: max_pw_passlen
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: ld returned 8 exit status

请问怎么样才能在AIX下用g++进行静态链接,以避免依赖于动态库?
...全文
434 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
DesireFish 2009-04-15
  • 打赏
  • 举报
回复
可能缺少什么库的.a文件吧
老邓 2009-04-14
  • 打赏
  • 举报
回复
有时,因为你需要链接的其他静态库使用了动态库,即:不能加-static
则你的程序也不能使用-static
否则链接错误。
  • 打赏
  • 举报
回复
http://bbs.chinaunix.net/viewthread.php?tid=526984

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧