ros2 galactic package with custom lib inside returns undefined reference
hi, i try to build a ros2 galactic package with code from waveshare ad/da raspberry pi hat (https://www.waveshare.com/wiki/High-P...) . The package and lib compiles, but it does not link, it returns undefined reference
[ 40%] Building C object CMakeFiles/ADS1256.dir/src/ADS1256.c.o
[ 60%] Linking C shared library libADS1256.so
[ 60%] Built target ADS1256
Scanning dependencies of target ros2_galactic_waveshare_adc_node
[ 80%] Building CXX object CMakeFiles/ros2_galactic_waveshare_adc_node.dir/src/ros2_galactic_waveshare_adc_node.cpp.o
[100%] Linking CXX executable ros2_galactic_waveshare_adc_node
/usr/bin/ld: CMakeFiles/ros2_galactic_waveshare_adc_node.dir/src/ros2_galactic_waveshare_adc_node.cpp.o: in function `WaveshareAdcPublisher::WaveshareAdcPublisher()':
ros2_galactic_waveshare_adc_node.cpp:(.text._ZN21WaveshareAdcPublisherC2Ev[_ZN21WaveshareAdcPublisherC5Ev]+0x2de): undefined reference to `DEV_ModuleInit()'
/usr/bin/ld: ros2_galactic_waveshare_adc_node.cpp:(.text._ZN21WaveshareAdcPublisherC2Ev[_ZN21WaveshareAdcPublisherC5Ev]+0x2e3): undefined reference to `ADS1256_init()'
/usr/bin/ld: ros2_galactic_waveshare_adc_node.cpp:(.text._ZN21WaveshareAdcPublisherC2Ev[_ZN21WaveshareAdcPublisherC5Ev]+0x2f5): undefined reference to `DEV_ModuleExit()'
/usr/bin/ld: CMakeFiles/ros2_galactic_waveshare_adc_node.dir/src/ros2_galactic_waveshare_adc_node.cpp.o: in function `WaveshareAdcPublisher::timer_callback()':
ros2_galactic_waveshare_adc_node.cpp:(.text._ZN21WaveshareAdcPublisher14timer_callbackEv[_ZN21WaveshareAdcPublisher14timer_callbackEv]+0x4d): undefined reference to `ADS1256_GetAll(unsigned int*)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ros2_galactic_waveshare_adc_node.dir/build.make:138: ros2_galactic_waveshare_adc_node] Error 1
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/ros2_galactic_waveshare_adc_node.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Failed <<< ros2_galactic_waveshare_adc [9.83s, exited with code 2]
What do i miss in my CMakeLists.txt file that it could build ? My CMakeLists.txt file and code is here: https://github.com/flobotics/ros2_gal...
thanks in advance flo
Edit:
i put the .c files into a separate ros2 lib package and in my package i do e.g. find_package() and it does find it
-- Found ros2_galactic_waveshare_adc_lib: 0.0.0 (/home/ros2/dev_ws/install/ros2_galactic_waveshare_adc_lib/share/ros2_galactic_waveshare_adc_lib/cmake)
i use
ament_target_dependencies(ros2_galactic_waveshare_adc_node
rclcpp
std_msgs
ros2_galactic_waveshare_adc_interfaces
ros2_galactic_waveshare_adc_lib
)
but then i get:
[ 50%] Linking CXX executable ros2_galactic_waveshare_adc_node
/usr/bin/ld: CMakeFiles/ros2_galactic_waveshare_adc_node.dir/src/ros2_galactic_waveshare_adc_node.cpp.o: in function `WaveshareAdcPublisher::WaveshareAdcPublisher()':
ros2_galactic_waveshare_adc_node.cpp:(.text._ZN21WaveshareAdcPublisherC2Ev[_ZN21WaveshareAdcPublisherC5Ev]+0x2de): undefined reference to `DEV_ModuleInit()'
/usr/bin/ld: ros2_galactic_waveshare_adc_node.cpp:(.text._ZN21WaveshareAdcPublisherC2Ev[_ZN21WaveshareAdcPublisherC5Ev]+0x2e3): undefined reference to `ADS1256_init()'
i read many, also https://answers.ros.org/question/3509...
but also that does not work ??
Edit 2: if i use colcon --log-level=10 build i can see that there is no "-lros2_galactic_waveshare_adc_lib" for the linker, and so the linker returns undefined reference. I testet the ros2-build lib with a test main.c file, and only when i miss "-lros2_galactic_waveshare_adc_lib" in my gcc build command, it returns undefined reference.
How do i add a compiler or linker option?
add_compile_option() does not seem to work?