[BUG] Error occurred when I use colcon build in depthai-core project
Describe the bug
when I use colcon build to build depthai-core, some ld errors occurred.
-
OS Version: Ubuntu22.04
-
ROS Version: ros2 humble
-
Branch: ros-release
Minimal Reproducible Example
cd ~/ws_other/depthai-core/src
git clone https://github.com/luxonis/depthai-core.git -b ros-release --recursive
cd ../
colcon build
Result:
/usr/bin/ld: /home/qiguanxiao/.hunter/_Base/16cc954/21498a3/132317e/Install/lib/libbz2.a(bzlib.c.o): warning: relocation against `BZ2_crc32Table' in read-only section `.text'
/usr/bin/ld: /home/qiguanxiao/.hunter/_Base/16cc954/21498a3/132317e/Install/lib/libbz2.a(compress.c.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/depthai-core.dir/build.make:1424: libdepthai-core.so] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:172: CMakeFiles/depthai-core.dir/all] Error 2
here is my installed libbz2.
libbz2-dev/jammy,now 1.0.8-5build1 amd64 [installed,automatic] libbz2-1.0/jammy,now 1.0.8-5build1 amd64 [installed,automatic]
Expected behavior The package should be build corrcetly.
Additional context
I tried to fix this error. After modifying ~/ws_other/depthai-core/src/depthai-core/cmake/Hunter/config.cmake, it can be built correctly.
Here is the modified file.
hunter_config(
BZip2
VERSION "1.0.8-p0"
CMAKE_ARGS # new
CMAKE_C_FLAGS=-fPIC # new 为C代码启用PIC
CMAKE_CXX_FLAGS=-fPIC # new 为C++代码启用PIC
)
Hi, thanks for the report, I'm not able to reproduce it locally but most likely could be caused by hunter artifacts from earlier build if depthai-core has been built without FPIC. Please try removing hunter cache directory (~/.hunter) before building and see if that helps