gcc / -Wl

默认情况下,GCC / G++ 链接时优先链接动态库,如果没有动态库,则链接相应的静态库。同时,GCC / G++ 也提供了链接选项 -Wl,-Bstatic-Wl,-Bdynamic 供用户指定链接动态库或者静态库。

  • -Wl,-Bstatic 指示跟在后面的 -lxxx 选项链接的都是静态库。
  • -Wl,-Bdynamic 指示跟在后面的 -lxxx 选项链接的都是动态库。

栗子:

-Wl,-Bstatic -llog4cplus -lpcap -lpgm -lxerces-c -Wl,-Bdynamic -lnl-3 -ldbus-1 -libverbs -lcurl -lhiredis -Wl,--as-needed

-Wl,-Bstatic 后面的库是静态链接的;  -Wl,-Bdynamic 后面的都是动态链接的。

原理上讲,Wl 后面的东西是作为参数传递给链接器 ld 。

The -Wl,xxx option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So

"gcc -Wl,aaa,bbb,ccc"  eventually becomes a linker call "ld aaa bbb ccc"

转载:GCC -Wl选项_wqfhenanxc的专栏-CSDN博客

(SAW:Game Over!)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CMake Error at /home/sniper/anaconda3/envs/yolov8/lib/python3.8/site-packages/cmake/data/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message): The C compiler "/usr/bin/gcc" is not able to compile a simple test program. It fails with the following output: Change Dir: /opt/projects/tensorrt-alpha/yolov8/build/CMakeFiles/CMakeScratch/TryCompile-TrXrKM Run Build Command(s):/usr/bin/make -f Makefile cmTC_7d457/fast && /usr/bin/make -f CMakeFiles/cmTC_7d457.dir/build.make CMakeFiles/cmTC_7d457.dir/build make[1]: 进入目录“/opt/projects/tensorrt-alpha/yolov8/build/CMakeFiles/CMakeScratch/TryCompile-TrXrKM” Building C object CMakeFiles/cmTC_7d457.dir/testCCompiler.c.o /usr/bin/gcc --sysroot=/usr/ -march=x86-64 -o CMakeFiles/cmTC_7d457.dir/testCCompiler.c.o -c /opt/projects/tensorrt-alpha/yolov8/build/CMakeFiles/CMakeScratch/TryCompile-TrXrKM/testCCompiler.c Linking C executable cmTC_7d457 /home/sniper/anaconda3/envs/yolov8/lib/python3.8/site-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7d457.dir/link.txt --verbose=1 /usr/bin/gcc --sysroot=/usr/ -march=x86-64 -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/sniper/anaconda3/lib -Wl,-rpath-link,/home/sniper/anaconda3/lib -L/home/sniper/anaconda3/lib CMakeFiles/cmTC_7d457.dir/testCCompiler.c.o -o cmTC_7d457 /usr/bin/ld: 找不到 /lib/x86_64-linux-gnu/libc.so.6 于 /usr/ 内部 /usr/bin/ld: 找不到 /usr/lib/x86_64-linux-gnu/libc_nonshared.a 于 /usr/ 内部 /usr/bin/ld: 找不到 /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 于 /usr/ 内部 collect2: error: ld returned 1 exit status make[1]: *** [CMakeFiles/cmTC_7d457.dir/build.make:99:cmTC_7d457] 错误 1 make[1]: 离开目录“/opt/projects/tensorrt-alpha/yolov8/build/CMakeFiles/CMakeScratch/TryCompile-TrXrKM” make: *** [Makefile:127:cmTC_7d457/fast] 错误 2 CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:25 (PROJECT) -- Configuring incomplete, errors occurred!
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值