Hello and thanks in advance for the help,
I have a linking issue with my cmake that I don't get. I'm trying to include a shared lib(modbuspp) in submodule which require another shared lib(libmodbus) on my computer. It seem simple but during exec linking it give me undefined reference to my computer lib (libmodbus) when I did add the includes. Does anyone has an idea why ? Here is my Cmake:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(This test)
project(${This} VERSION "0.1.0")
configure_file("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_SOURCE_DIR}/src/config.h")
#enable_testing()
#add_subdirectory(googletest)
#add_subdirectory(test)
file(GLOB Sources
"src/*.hpp"
"src/*.cpp"
)
add_executable(${This} ${Sources})
find_package(nlohmann_json 3.2.0 REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(Modbus REQUIRED)
message(TROLOLO:${MODBUS_INCLUDE_DIRS})
include_directories(${MODBUS_INCLUDE_DIRS})
#target_include_directories(${This} PRIVATE ${MODBUS_INCLUDE_DIRS})
#work on libmodbuspp exemple "-shared -fPIC -pthread -I/usr/local/include -I/usr/include/modbus -L/usr/local/lib -lmodbuspp -lmodbus"
#Configure: cmake -DMODBUSPP_USE_EXTERNAL_JSON=ON -DMODBUSPP_WITH_STATIC=1 -DINSTALL_LIB_DIR=libs -DMODBUSPP_UNIT_TESTS=0 -S . -B build
add_subdirectory(external/libmodbuspp)
include_directories(external/libmodbuspp/include)
#target_include_directories(${This} PRIVATE external/libmodbuspp/include)
link_directories(${This} PRIVATE ${PROJECT_BINARY_DIR}/external/libmodbuspp/lib)
target_link_libraries(${This} PRIVATE ${MODBUS_LIBRARIES} modbuspp-shared)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${This} PUBLIC Threads::Threads)
And here are the compile error:
Scanning dependencies of target objlib
[ 4%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/bufferedslave.cpp.o
[ 9%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/device.cpp.o
[ 14%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/master.cpp.o
[ 19%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/message.cpp.o
[ 23%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/netlayer.cpp.o
[ 28%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/request.cpp.o
[ 33%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/response.cpp.o
[ 38%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/router.cpp.o
[ 42%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/rtulayer.cpp.o
[ 47%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/server.cpp.o
/home/aurelia/git/test/external/libmodbuspp/src/server.cpp: In static member function ‘static void* Modbus::Server::Private::loop(std::future<void>, Modbus::Server::Private*)’:
/home/aurelia/git/test/external/libmodbuspp/src/server.cpp:434:3: warning: no return statement in function returning non-void [-Wreturn-type]
434 | }
| ^
[ 52%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/slave.cpp.o
[ 57%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/tcplayer.cpp.o
[ 61%] Building CXX object external/libmodbuspp/lib/CMakeFiles/objlib.dir/__/src/timeout.cpp.o
[ 61%] Built target objlib
Scanning dependencies of target modbuspp-shared
[ 66%] Linking CXX shared library libmodbuspp.so
[ 66%] Built target modbuspp-shared
Scanning dependencies of target test
[ 71%] Building CXX object CMakeFiles/test.dir/src/StaticDI.cpp.o
[ 76%] Building CXX object CMakeFiles/test.dir/src/StaticDO.cpp.o
[ 80%] Building CXX object CMakeFiles/test.dir/src/conf.cpp.o
[ 85%] Building CXX object CMakeFiles/test.dir/src/main.cpp.o
[ 90%] Building CXX object CMakeFiles/test.dir/src/modbusServer.cpp.o
[ 95%] Linking CXX executable test
/usr/bin/ld: external/libmodbuspp/lib/libmodbuspp.so.1.0.0: undefined reference to `modbus_rtu_set_rts_delay'
/usr/bin/ld: external/libmodbuspp/lib/libmodbuspp.so.1.0.0: undefined reference to `modbus_get_byte_timeout'
/usr/bin/ld: external/libmodbuspp/lib/libmodbuspp.so.1.0.0: undefined reference to `modbus_rtu_get_rts'
/usr/bin/ld: external/libmodbuspp/lib/libmodbuspp.so.1.0.0: undefined reference to `modbus_close'
/usr/bin/ld: external/libmodbuspp/lib/libmodbuspp.so.1.0.0: undefined reference to `modbus_mapping_free'
/usr/bin/ld: external/libmodbuspp/lib/libmodbuspp.so.1.0.0: undefined reference to `modbus_set_indication_time
But all those reference can be found in the include that was linked with include_directories :
/usr/include/modbus$ grep rtu_set_rts_delay ./*
./modbus-rtu.h:MODBUS_API int modbus_rtu_set_rts_delay(modbus_t *ctx, int us);
Related
I have been trying on and off for the past year to import the NLopt library into my work. I have been unsuccessful, and I am desperate for help.
Here is some of my CMAKE file
cmake_minimum_required(VERSION 3.21)
project(DynamicRRT)
set(CMAKE_CXX_STANDARD 17)
set(CONAN_CMAKE_CXX_STANDARD 17)
include_directories(/opt/homebrew/Cellar/eigen/3.4.0_1/include/eigen3/)
find_library(nlopt /Users/brandon/Extern/nlopt_install/ NAMES libnlopt nlopt NLopt)
include_directories(/Users/brandon/Extern/nlopt_install/include/ )
link_directories(/Users/brandon/Extern/nlopt_install/include/ )
#INCLUDE_DIRECTORIES(/Users/brandon/CLionProjects/nlopt/)
#INCLUDE_DIRECTORIES(/opt/homebrew/Cellar/nlopt/2.7.1/include/)
#include_directories(/usr/local/include/)
#add_library(nlopt /Users/brandon/Extern/nlopt_install/include)
#add_compile_options(-Wa,-mbig-obj)¡
add_executable(DynamicRRT main.cpp utilities.cpp utilities.h rrt_star.cpp rrt_star.h tree.cpp tree.h Nodes.cpp Nodes.h Obstacles.cpp Obstacles.h macro_rrt_star.cpp macro_rrt_star.h collisions.cpp collisions.h dynamic_rrt_star.cpp dynamic_rrt_star.h trajectory.cpp trajectory.h transformer.cpp transformer.h print_utilities.cpp print_utilities.h random_utilities.cpp random_utilities.h)# inverse_kinematics.cpp inverse_kinematics.h)# rrt_star.cpp rrt_star.h)#rrt_star_util.cpp rrt_star_util.h
target_link_libraries(DynamicRRT nlopt)
You can see that I've commented out a number of attempts at getting this imported. CMake does not throw any errors. However, if I try building the project, I get:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/brandonmeng/CLionProjects/DynamicRRT/cmake-build-default-gcc --target all -- -j 8
[ 14%] Building CXX object CMakeFiles/DynamicRRT.dir/Obstacles.cpp.o
[ 14%] Building CXX object CMakeFiles/DynamicRRT.dir/utilities.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/rrt_star.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/macro_rrt_star.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/Nodes.cpp.o
[ 42%] Building CXX object CMakeFiles/DynamicRRT.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/DynamicRRT.dir/tree.cpp.o
[ 57%] Building CXX object CMakeFiles/DynamicRRT.dir/collisions.cpp.o
[ 64%] Building CXX object CMakeFiles/DynamicRRT.dir/dynamic_rrt_star.cpp.o
[ 71%] Building CXX object CMakeFiles/DynamicRRT.dir/trajectory.cpp.o
[ 78%] Building CXX object CMakeFiles/DynamicRRT.dir/transformer.cpp.o
[ 85%] Building CXX object CMakeFiles/DynamicRRT.dir/print_utilities.cpp.o
[ 92%] Building CXX object CMakeFiles/DynamicRRT.dir/random_utilities.cpp.o
[100%] Linking CXX executable bin/DynamicRRT
ld: library not found for -lnlopt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/DynamicRRT] Error 1
make[1]: *** [CMakeFiles/DynamicRRT.dir/all] Error 2
make: *** [all] Error 2
link_directories(/Users/brandon/Extern/nlopt_install/include/ )
The library to link with is likely not in the include directory with the header files. It's more likely they're in a lib directory:
link_directories(/Users/brandon/Extern/nlopt_install/lib)
So I have a directory that's formatted as follows:
Project:
- src
- a.cpp
- b.cpp
- c.cpp
- include
- h.cpp
- h.hpp
How would I get CMake to include h.hpp in the files in the source folder? I tried doing include_directories(include) but CMake is still unable to find the file. I also tried changing the include directive in a.cpp to #include "../include/h.hpp". However, none of these solutions have worked.
EDIT:
The output is:
[build] Consolidate compiler generated dependencies of target a
[build] Consolidate compiler generated dependencies of target c
[build] Consolidate compiler generated dependencies of target b
[build] [ 16%] Building CXX object CMakeFiles/b.dir/src/b.cpp.o
[build] [ 33%] Building CXX object CMakeFiles/c.dir/src/c.cpp.o
[build] [ 50%] Building CXX object CMakeFiles/a.dir/src/a.cpp.o
[build] [ 66%] Linking CXX executable a
[build] [ 83%] Linking CXX executable c
[build] [100%] Linking CXX executable b
[build] /usr/bin/ld: CMakeFiles/a.dir/src/a.cpp.o: in function `func(...)':
[build] ../a.cpp:55: undefined reference to `func(...)'
[build] /usr/bin/ld: a.cpp:58: undefined reference to `func(...)'
Note that func is a function with an implementation provided in h.cpp.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
project(proj)
find_package(fmt CONFIG REQUIRED)
find_package(CUDAToolkit REQUIRED)
link_libraries(
fmt::fmt CUDA::nvrtc CUDA::cuda_driver CUDA::cudart
)
include_directories(include)
add_executable(a ${CMAKE_CURRENT_SOURCE_DIR}/src/a.cpp)
add_executable(b ${CMAKE_CURRENT_SOURCE_DIR}/src/b.cpp)
add_executable(c ${CMAKE_CURRENT_SOURCE_DIR}/src/c.cpp)
You should add h.cpp as a source for each executable that uses functions from h.hpp:
add_executable(a ${CMAKE_CURRENT_SOURCE_DIR}/src/a.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/h.cpp)
add_executable(b ${CMAKE_CURRENT_SOURCE_DIR}/src/b.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/h.cpp)
add_executable(c ${CMAKE_CURRENT_SOURCE_DIR}/src/c.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/h.cpp)
As you have said,
func is a function with an implementation provided in h.cpp
so you need to add that implementation to your executables
I've compiled a c++ dynamic library using cmake and I want to add to my iOS app. But the header file directory of this .framework is empty, I refer to the CMakeFiles written in the cmake documentation. I don't know where the problem is?
Any help would be greatly appreciated.
Here is my CMake script
cmake_minimum_required(VERSION 3.2)
project(Xml C CXX)
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(HEADERS
./include
)
include_directories(
${HEADERS}
)
aux_source_directory(. DIR_SRCS)
add_library(Xml SHARED
${DIR_SRCS}
${HEADERS}
)
set_target_properties(Xml PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION CXX
PUBLIC_HEADER ${HEADERS}
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
)
Compilation progress
Scanning dependencies of target Xml
[ 10%] Building CXX object CMakeFiles/Xml.dir/ILock.cpp.o
[ 20%] Building CXX object CMakeFiles/Xml.dir/ParamSet.cpp.o
[ 30%] Building CXX object CMakeFiles/Xml.dir/StringConvert.cpp.o
[ 40%] Building CXX object CMakeFiles/Xml.dir/XmlFile.cpp.o
[ 50%] Building CXX object CMakeFiles/Xml.dir/XmlInterface.cpp.o
[ 60%] Building CXX object CMakeFiles/Xml.dir/tinystr.cpp.o
[ 70%] Building CXX object CMakeFiles/Xml.dir/tinyxml.cpp.o
[ 80%] Building CXX object CMakeFiles/Xml.dir/tinyxmlerror.cpp.o
[ 90%] Building CXX object CMakeFiles/Xml.dir/tinyxmlparser.cpp.o
[100%] Linking CXX shared library Xml.framework/Xml
Copying OS X content Xml.framework/Versions/CXX/Headers/include
[100%] Built target Xml
Compiled dynamic library
The issue is solved. CMake can't get all header files with the ./include syntax. The following is a modified CMake script.
set(HEADERS
./include/a.h
./include/b.h
./include/c.h
)
include_directories(
./include
)
aux_source_directory(. DIR_SRCS)
add_library(Xml SHARED
${DIR_SRCS}
${HEADERS}
)
set_target_properties(Xml PROPERTIES
FRAMEWORK TRUE
PUBLIC_HEADER "${HEADERS}"
)
I need help. I try to build JRTPLIB 3.1.1 with SRTP 2.1.0 and OpenSSL 1.1.0 but got linker error while try to make JRTPLIB.
Dependencies:
Debian 9 (also tried on Ubuntu 16.04 LTS)
JRTPLIB v.3_1_11(from git+changes)
JTHREAD v.1_3_3 (from git)
LIBSRTP v.2_1_0 (by tag)
LIBSSL v.1_1_0 Stable (by branch)
Source changes:
JRTPLIB v.3_1_11 (from git): changed srtp to srtp2; link to lib source archive: https://drive.google.com/drive/folders/0B_Q0HXvHrCzabVpsSUp0TXNka1U?usp=sharing
Cmake settings (image cmake_JRTPLIB.JPG): https://drive.google.com/drive/folders/0B_Q0HXvHrCzabVpsSUp0TXNka1U?usp=sharing
Build:
1)OpenSSL:
build from source and also tried on a Virtual Machine to install libssl1.1 and libssl-dev by sudo apt-get install libssl1.1 libssl-dev)
2)libSRTP:
$./configure --enable-debug-logging --enable-log-stdout --enable-openssl
3)JTHREAD: build with cmake
4)JRTPLIB: Cmake config - see image cmake_JRTPLIB.JPG
$make
Error log:
Scanning dependencies of target jrtplib-static
[ 1%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpapppacket.cpp.o
[ 2%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpbyepacket.cpp.o
[ 3%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpcompoundpacket.cpp.o
[ 4%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpcompoundpacketbuilder.cpp.o
[ 4%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcppacket.cpp.o
[ 5%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcppacketbuilder.cpp.o
[ 6%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcprrpacket.cpp.o
[ 7%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpscheduler.cpp.o
[ 8%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpsdesinfo.cpp.o
[ 8%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpsdespacket.cpp.o
[ 9%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtcpsrpacket.cpp.o
[ 10%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpcollisionlist.cpp.o
[ 11%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpdebug.cpp.o
[ 12%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtperrors.cpp.o
[ 12%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpinternalsourcedata.cpp.o
[ 13%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpipv4address.cpp.o
[ 14%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpipv6address.cpp.o
[ 15%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpipv4destination.cpp.o
[ 16%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpipv6destination.cpp.o
[ 16%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtplibraryversion.cpp.o
[ 17%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtppacket.cpp.o
[ 18%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtppacketbuilder.cpp.o
[ 19%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtppollthread.cpp.o
[ 20%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtprandom.cpp.o
[ 20%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtprandomrand48.cpp.o
[ 21%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtprandomrands.cpp.o
[ 22%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtprandomurandom.cpp.o
[ 23%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpsession.cpp.o
[ 24%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpsessionparams.cpp.o
[ 25%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpsessionsources.cpp.o
[ 25%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpsourcedata.cpp.o
[ 26%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpsources.cpp.o
[ 27%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtptimeutilities.cpp.o
[ 28%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpudpv4transmitter.cpp.o
[ 29%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpudpv6transmitter.cpp.o
[ 29%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpbyteaddress.cpp.o
[ 30%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpexternaltransmitter.cpp.o
[ 31%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpsecuresession.cpp.o
[ 32%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtpabortdescriptors.cpp.o
[ 33%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtptcpaddress.cpp.o
[ 33%] Building CXX object src/CMakeFiles/jrtplib-static.dir/rtptcptransmitter.cpp.o
[ 34%] Building CXX object src/CMakeFiles/jrtplib-static.dir/extratransmitters/rtpfaketransmitter.cpp.o
[ 35%] Linking CXX static library libjrtp.a
[ 35%] Built target jrtplib-static
Scanning dependencies of target jrtplib-shared
[ 35%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpapppacket.cpp.o
[ 36%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpbyepacket.cpp.o
[ 37%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpcompoundpacket.cpp.o
[ 38%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpcompoundpacketbuilder.cpp.o
[ 39%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcppacket.cpp.o
[ 39%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcppacketbuilder.cpp.o
[ 40%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcprrpacket.cpp.o
[ 41%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpscheduler.cpp.o
[ 42%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpsdesinfo.cpp.o
[ 43%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpsdespacket.cpp.o
[ 44%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtcpsrpacket.cpp.o
[ 44%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpcollisionlist.cpp.o
[ 45%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpdebug.cpp.o
[ 46%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtperrors.cpp.o
[ 47%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpinternalsourcedata.cpp.o
[ 48%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpipv4address.cpp.o
[ 48%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpipv6address.cpp.o
[ 49%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpipv4destination.cpp.o
[ 50%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpipv6destination.cpp.o
[ 51%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtplibraryversion.cpp.o
[ 52%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtppacket.cpp.o
[ 52%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtppacketbuilder.cpp.o
[ 53%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtppollthread.cpp.o
[ 54%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtprandom.cpp.o
[ 55%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtprandomrand48.cpp.o
[ 56%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtprandomrands.cpp.o
[ 56%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtprandomurandom.cpp.o
[ 57%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpsession.cpp.o
[ 58%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpsessionparams.cpp.o
[ 59%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpsessionsources.cpp.o
[ 60%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpsourcedata.cpp.o
[ 60%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpsources.cpp.o
[ 61%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtptimeutilities.cpp.o
[ 62%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpudpv4transmitter.cpp.o
[ 63%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpudpv6transmitter.cpp.o
[ 64%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpbyteaddress.cpp.o
[ 64%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpexternaltransmitter.cpp.o
[ 65%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpsecuresession.cpp.o
[ 66%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpabortdescriptors.cpp.o
[ 67%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtptcpaddress.cpp.o
[ 68%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtptcptransmitter.cpp.o
[ 69%] Building CXX object src/CMakeFiles/jrtplib-shared.dir/extratransmitters/rtpfaketransmitter.cpp.o
[ 69%] Linking CXX shared library libjrtp.so
[ 69%] Built target jrtplib-shared
Scanning dependencies of target example4
[ 69%] Building CXX object examples/CMakeFiles/example4.dir/example4.cpp.o
[ 70%] Linking CXX executable example4
[ 70%] Built target example4
Scanning dependencies of target example2
[ 71%] Building CXX object examples/CMakeFiles/example2.dir/example2.cpp.o
[ 72%] Linking CXX executable example2
[ 72%] Built target example2
Scanning dependencies of target example5
[ 73%] Building CXX object examples/CMakeFiles/example5.dir/example5.cpp.o
[ 74%] Linking CXX executable example5
[ 74%] Built target example5
Scanning dependencies of target example8
[ 75%] Building CXX object examples/CMakeFiles/example8.dir/example8.cpp.o
[ 76%] Linking CXX executable example8
[ 76%] Built target example8
Scanning dependencies of target example1
[ 77%] Building CXX object examples/CMakeFiles/example1.dir/example1.cpp.o
[ 77%] Linking CXX executable example1
[ 77%] Built target example1
Scanning dependencies of target example6
[ 78%] Building CXX object examples/CMakeFiles/example6.dir/example6.cpp.o
[ 78%] Linking CXX executable example6
[ 78%] Built target example6
Scanning dependencies of target example7
[ 79%] Building CXX object examples/CMakeFiles/example7.dir/example7.cpp.o
[ 80%] Linking CXX executable example7
/usr/local/lib/libsrtp2.a(datatypes.o): In function octet_string_set_to_zero': datatypes.c:(.text+0x1d91): undefined reference toOPENSSL_cleanse'
/usr/local/lib/libsrtp2.a(aes_icm_ossl.o): In function srtp_aes_icm_openssl_set_iv': aes_icm_ossl.c:(.text+0x77): undefined reference toEVP_EncryptInit_ex'
/usr/local/lib/libsrtp2.a(aes_icm_ossl.o): In function srtp_aes_icm_openssl_encrypt': aes_icm_ossl.c:(.text+0xe8): undefined reference toEVP_EncryptUpdate'
aes_icm_ossl.c:(.text+0x113): undefined reference to EVP_EncryptFinal_ex' /usr/local/lib/libsrtp2.a(aes_icm_ossl.o): In functionsrtp_aes_icm_openssl_context_init':
aes_icm_ossl.c:(.text+0x1f9): undefined reference to EVP_aes_128_ctr' aes_icm_ossl.c:(.text+0x20d): undefined reference toEVP_EncryptInit_ex'
aes_icm_ossl.c:(.text+0x231): undefined reference to EVP_aes_256_ctr' aes_icm_ossl.c:(.text+0x241): undefined reference toEVP_aes_192_ctr'
/usr/local/lib/libsrtp2.a(aes_icm_ossl.o): In function srtp_aes_icm_openssl_dealloc': aes_icm_ossl.c:(.text+0x26c): undefined reference toEVP_CIPHER_CTX_free'
/usr/local/lib/libsrtp2.a(aes_icm_ossl.o): In function srtp_aes_icm_openssl_alloc': aes_icm_ossl.c:(.text+0x36a): undefined reference toEVP_CIPHER_CTX_new'
/usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In function srtp_aes_gcm_openssl_get_tag': aes_gcm_ossl.c:(.text+0x18): undefined reference toEVP_Cipher'
aes_gcm_ossl.c:(.text+0x2c): undefined reference to EVP_CIPHER_CTX_ctrl' /usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In functionsrtp_aes_gcm_openssl_set_aad':
aes_gcm_ossl.c:(.text+0x71): undefined reference to EVP_CIPHER_CTX_ctrl' aes_gcm_ossl.c:(.text+0x81): undefined reference toEVP_Cipher'
/usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In function srtp_aes_gcm_openssl_context_init': aes_gcm_ossl.c:(.text+0xeb): undefined reference toEVP_aes_256_gcm'
aes_gcm_ossl.c:(.text+0x102): undefined reference to EVP_CipherInit_ex' aes_gcm_ossl.c:(.text+0x129): undefined reference toEVP_aes_128_gcm'
/usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In function srtp_aes_gcm_openssl_dealloc': aes_gcm_ossl.c:(.text+0x147): undefined reference toEVP_CIPHER_CTX_free'
/usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In function srtp_aes_gcm_openssl_encrypt': aes_gcm_ossl.c:(.text+0x19e): undefined reference toEVP_Cipher'
/usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In function srtp_aes_gcm_openssl_decrypt': aes_gcm_ossl.c:(.text+0x1e3): undefined reference toEVP_CIPHER_CTX_ctrl'
aes_gcm_ossl.c:(.text+0x1f9): undefined reference to EVP_Cipher' aes_gcm_ossl.c:(.text+0x208): undefined reference toEVP_Cipher'
/usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In function srtp_aes_gcm_openssl_set_iv': aes_gcm_ossl.c:(.text+0x293): undefined reference toEVP_CipherInit_ex'
aes_gcm_ossl.c:(.text+0x2c1): undefined reference to EVP_CIPHER_CTX_ctrl' aes_gcm_ossl.c:(.text+0x2db): undefined reference toEVP_CIPHER_CTX_ctrl'
aes_gcm_ossl.c:(.text+0x2f2): undefined reference to EVP_CIPHER_CTX_ctrl' /usr/local/lib/libsrtp2.a(aes_gcm_ossl.o): In functionsrtp_aes_gcm_openssl_alloc':
aes_gcm_ossl.c:(.text+0x3cb): undefined reference to EVP_CIPHER_CTX_new' /usr/local/lib/libsrtp2.a(hmac_ossl.o): In functionsrtp_hmac_start':
hmac_ossl.c:(.text+0xe): undefined reference to HMAC_Init_ex' /usr/local/lib/libsrtp2.a(hmac_ossl.o): In functionsrtp_hmac_update':
hmac_ossl.c:(.text+0x61): undefined reference to HMAC_Update' /usr/local/lib/libsrtp2.a(hmac_ossl.o): In functionsrtp_hmac_init':
hmac_ossl.c:(.text+0x8e): undefined reference to EVP_sha1' hmac_ossl.c:(.text+0xa2): undefined reference toHMAC_Init_ex'
/usr/local/lib/libsrtp2.a(hmac_ossl.o): In function srtp_hmac_dealloc': hmac_ossl.c:(.text+0xc9): undefined reference toHMAC_CTX_free'
/usr/local/lib/libsrtp2.a(hmac_ossl.o): In function srtp_hmac_compute': hmac_ossl.c:(.text+0x129): undefined reference toHMAC_Update'
hmac_ossl.c:(.text+0x142): undefined reference to HMAC_Final' /usr/local/lib/libsrtp2.a(hmac_ossl.o): In functionsrtp_hmac_alloc':
hmac_ossl.c:(.text+0x21c): undefined reference to `HMAC_CTX_new'
collect2: error: ld returned 1 exit status
examples/CMakeFiles/example7.dir/build.make:96: ошибка выполнения рецепта для цели «examples/example7»
make[2]: *** [examples/example7] Ошибка 1
CMakeFiles/Makefile2:415: ошибка выполнения рецепта для цели «examples/CMakeFiles/example7.dir/all»
make[1]: *** [examples/CMakeFiles/example7.dir/all] Ошибка 2
Makefile:127: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2
I've been trying to 'hack' 2 programs together and one of them (openTLD) uses cmake. I've been reading up and working on this issue for a bit now and can't seem to sort it.
When I 'make' where there is no instantiation of the cpp object it compiles fine, when I have an object (that relies on libusb) that I hacked in I'm getting linking (I think) errors.
My CMakeLists (added bits delimeted by ** or CAPS)
#Set minimum version requered
cmake_minimum_required(VERSION 2.4.6)
#just to avoid the warning
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
#set project name
project(TLD)
#Append path to the module path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../cmake/Modules/")
#OpenCV
find_package(OpenCV REQUIRED)
#** ADDED **
find_package(libusb-1.0 REQUIRED)
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../lib)
#set the include directories **CHANGED** added libusb
include_directories (${PROJECT_SOURCE_DIR}/../include ${LIBUSB_1_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
#** ADDED **
SET(CMAKE_CXX_FLAGS "-lusb-1.0")
#libraries
add_library(tld_utils tld_utils.cpp)
add_library(LKTracker LKTracker.cpp)
add_library(ferNN FerNNClassifier.cpp)
add_library(tld TLD.cpp)
# **CHANGED** THIS CLASS COMPILES
add_library(servo servo.cpp)
#executables
# ** WHEN I TRY TO ISTANTIATE 'SERVO' IN 'tld.cpp' THAT IS ISTANTIATED THIS CLASS I GET PROBLEMS
add_executable(run_tld run_tld.cpp)
#link the libraries **CHANGED** added servo and libusb
target_link_libraries(run_tld tld LKTracker ferNN tld_utils servo ${libusb-1.0__LIBS} ${OpenCV_LIBS})
#set optimization level
set(CMAKE_BUILD_TYPE Release)
The output from terminal is :
lewis#lewis-desktop:~/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/build$ cmake ../src/
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found libusb-1.0:
-- - Includes: /usr/include/libusb-1.0
-- - Libraries: /usr/lib/x86_64-linux-gnu/libusb-1.0.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/build
lewis#lewis-desktop:~/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/build$ make
Scanning dependencies of target LKTracker
[ 16%] Building CXX object CMakeFiles/LKTracker.dir/LKTracker.o
Linking CXX static library /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libLKTracker.a
[ 16%] Built target LKTracker
Scanning dependencies of target ferNN
[ 33%] Building CXX object CMakeFiles/ferNN.dir/FerNNClassifier.o
Linking CXX static library /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libferNN.a
[ 33%] Built target ferNN
Scanning dependencies of target tld_utils
[ 50%] Building CXX object CMakeFiles/tld_utils.dir/tld_utils.o
Linking CXX static library /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libtld_utils.a
[ 50%] Built target tld_utils
Scanning dependencies of target servo
[ 66%] Building CXX object CMakeFiles/servo.dir/servo.o
Linking CXX static library /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libservo.a
[ 66%] Built target servo
Scanning dependencies of target tld
[ 83%] Building CXX object CMakeFiles/tld.dir/TLD.o
Linking CXX static library /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libtld.a
[ 83%] Built target tld
Scanning dependencies of target run_tld
[100%] Building CXX object CMakeFiles/run_tld.dir/run_tld.o
Linking CXX executable /home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/bin/run_tld
/home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libservo.a(servo.o): In function `servo::servo()':
servo.cpp:(.text+0xa): undefined reference to `libusb_init'
servo.cpp:(.text+0x1b): undefined reference to `libusb_get_device_list'
/home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libservo.a(servo.o): In function `servo::deviceMatchesVendorProduct(libusb_device*, unsigned short, unsigned short)':
servo.cpp:(.text+0x49): undefined reference to `libusb_get_device_descriptor'
/home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/lib/libservo.a(servo.o): In function `servo::setTarget(int)':
servo.cpp:(.text+0xc1): undefined reference to `libusb_get_device_descriptor'
servo.cpp:(.text+0xe3): undefined reference to `libusb_get_device_descriptor'
servo.cpp:(.text+0x105): undefined reference to `libusb_get_device_descriptor'
servo.cpp:(.text+0x143): undefined reference to `libusb_get_device_descriptor'
servo.cpp:(.text+0x170): undefined reference to `libusb_open'
servo.cpp:(.text+0x19c): undefined reference to `libusb_control_transfer'
servo.cpp:(.text+0x1a6): undefined reference to `libusb_close'
servo.cpp:(.text+0x1c2): undefined reference to `libusb_free_device_list'
servo.cpp:(.text+0x1ce): undefined reference to `libusb_exit'
collect2: ld returned 1 exit status
make[2]: *** [/home/lewis/Desktop/mcleanlewis-OPENTLD_blackbox-ce389c3/bin/run_tld] Error 1
make[1]: *** [CMakeFiles/run_tld.dir/all] Error 2
make: *** [all] Error 2
My servo.cpp file incase there is an issue with it (I'm not a cpp programmer and it's been hacked together)
#include <iostream>
#include <libusb-1.0/libusb.h>
#include "protocol.h"
#include "servo.h"
using namespace std;
int count=0;
const unsigned short vendorId = 0x1ffb;
unsigned short productIDArray[]={0x0089, 0x008a, 0x008b, 0x008c};
libusb_context *ctx=0;
libusb_device **device_list=0;
servo::servo(){
libusb_init(&ctx);
count=libusb_get_device_list(ctx, &device_list);
}
bool servo::deviceMatchesVendorProduct(libusb_device *device, unsigned short idVendor, unsigned short idProduct)
{
libusb_device_descriptor desc;
libusb_get_device_descriptor(device, &desc);
return idVendor == desc.idVendor && idProduct == desc.idProduct;
}
void servo::setTarget(int position)
{
for(int i=0;i<count;i++)
{
libusb_device *device=device_list[i];
{
for(int Id=0;Id<4;Id++)
{
if(deviceMatchesVendorProduct(device, vendorId, productIDArray[Id]))
{
libusb_device_handle *device_handle;
libusb_open(device, &device_handle);
libusb_control_transfer(device_handle, 0x40, REQUEST_SET_TARGET, position*4, 0, 0, 0, (ushort)5000);
libusb_close(device_handle);
break;
}
}
}
}
libusb_free_device_list(device_list, 0);
libusb_exit(ctx);
}
Thanks for any assistance or pointers.
This is indeed a linker error. It looks like you might have the wrong variable for the libusb-1.0 libraries. Try changing your target_link_libraries command to:
target_link_libraries(run_tld tld LKTracker ferNN tld_utils servo ${LIBUSB_1_LIBRARIES} ${OpenCV_LIBS})
You probably also should remove SET(CMAKE_CXX_FLAGS "-lusb-1.0"), since linking will be handled by the target_link_libraries command.