Ale*_*sas 5 c++ g++ shared-libraries raspberry-pi
我正在尝试执行用我自己的库编译的程序,但是当我执行该程序时,出现以下错误:
./a.out
./a.out: error while loading shared libraries: ../../lib-arm/libCustomLibrary.so: unexpected reloc type 0x03
Run Code Online (Sandbox Code Playgroud)
这只是在发布执行时发生,调试执行一切正常。
你认为这可能是哪里的问题?
CustomLibrary 库与以下参数链接:
-lSubLibrary -fPIC -Wl,-Bstatic -lboost_system -lboost_filesystem -lboost_thread -lpthread -Wl,-Bdynamic -lrt
Run Code Online (Sandbox Code Playgroud)
我为我的库附加了 lld unix 库命令输出。
ldd ../../lib-arm/libCustomLibrary.so
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0x76e5d000)
libSubLibrary.so => ../../lib-arm/libSubLibrary.so (0x76e2d000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0x76e10000)
libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0x76d3e000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x76ccd000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x76ca5000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x76b75000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0x76b6a000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x76b4b000)
/lib/ld-linux-armhf.so.3 (0x76f05000)
Run Code Online (Sandbox Code Playgroud)
从https://lists.linaro.org/pipermail/linaro-toolchain/2012-November/002939.html:
重定位类型 3 是 R_ARM_REL32,这是共享对象中不允许的静态重定位。你是如何创建共享库的?确保使用 -fPIC 编译所有进入其中的代码。
换句话说,您-fPIC在链接程序时使用,但在构建共享库时可能不会使用。