I am new to Cmake. I am using Ubuntu 20.
I build & installed dlt-daemon-2.18.8 locally (/home/map/third_party) and build Log library.
Following is the Content of Log library CMakeLists.txt
find_package(PkgConfig REQUIRED)
pkg_search_module(DLT automotive-dlt REQUIRED)
message("***** pkg_search_module DLT_MODULE_NAME = ${DLT_MODULE_NAME} *****")
message("***** pkg_search_module DLT_FOUND = ${DLT_FOUND} *****")
message("***** pkg_search_module DLT_LIBRARIES = ${DLT_LIBRARIES} *****")
message("***** pkg_search_module DLT_LINK_LIBRARIES = ${DLT_LINK_LIBRARIES} *****")
message("***** pkg_search_module DLT_LIBRARY_DIRS = ${DLT_LIBRARY_DIRS} *****")
message("***** pkg_search_module DLT_LDFLAGS = ${DLT_LDFLAGS} *****")
message("***** pkg_search_module DLT_LDFLAGS_OTHER = ${DLT_LDFLAGS_OTHER} *****")
message("***** pkg_search_module DLT_INCLUDE_DIRS = ${DLT_INCLUDE_DIRS} *****")
add_subdirectory(src)
Following is the part of CMakeLists.txt in src folder which is in Log folder(main CMAke file)
target_link_libraries(${PROJECT_NAME}
PUBLIC
${DLT_LIBRARIES}
ara::core-types
apd::Threads
)
Following is the output from Log library CMakeLists.txt & it looks ok.
-- Checking for one of the modules 'automotive-dlt'
***** pkg_search_module DLT_MODULE_NAME = automotive-dlt *****
***** pkg_search_module DLT_FOUND = 1 *****
***** pkg_search_module DLT_LIBRARIES = dlt;rt;pthread *****
***** pkg_search_module DLT_LINK_LIBRARIES = /home/map/third_party/lib/libdlt.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so *****
***** pkg_search_module DLT_LIBRARY_DIRS = /home/map/third_party/lib *****
***** pkg_search_module DLT_LDFLAGS = -L/home/map/third_party/lib;-ldlt;-lrt;-lpthread *****
***** pkg_search_module DLT_LDFLAGS_OTHER = *****
***** pkg_search_module DLT_INCLUDE_DIRS = /home/map/third_party/include/dlt;/home/map/third_party/include *****
-- Configuring done
After this, I am building 1 application & 2 Library using above mentioned Log library but it is failing to link with the following error
[100%] Linking CXX shared library libe2exf.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX shared library libe2e.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX executable execution-manager
/usr/bin/ld: cannot find -ldlt
If I install this two component (sudo apt-get install libdlt2 & sudo apt-get install libdlt-dev ) then 2 Libraries(libe2exf.so & libe2e.so) are building but failing application(execution-manager) with following error
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o): in function ara::log::LogStream::operator<<(ara::core::Span<ara::core::internal::Byte const, 18446744073709551615ul>)':log_stream.cpp:(.text+0xbaf): undefined reference to
dlt_user_log_write_sized_utf8_string'
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o): in function ara::log::LogStream::WithLocation(ara::core::internal::basic_string_view<char, std::char_traits<char> >, int)':log_stream.cpp:(.text+0xdc6): undefined reference to
dlt_user_log_write_sized_utf8_string'
I don't want to install libdlt2 & libdlt-dev and please let me know how to link above 1 application & 2 Library to /home/map/third_party/lib/libdlt.so;
Thanks in advanceHi,
I build & installed dlt-daemon-2.18.8 locally (/home/map/third_party) and build Log library.
Following is the Content of Log library CMakeLists.txt
find_package(PkgConfig REQUIRED)
pkg_search_module(DLT automotive-dlt REQUIRED)
message("***** pkg_search_module DLT_MODULE_NAME = ${DLT_MODULE_NAME} *****")
message("***** pkg_search_module DLT_FOUND = ${DLT_FOUND} *****")
message("***** pkg_search_module DLT_LIBRARIES = ${DLT_LIBRARIES} *****")
message("***** pkg_search_module DLT_LINK_LIBRARIES = ${DLT_LINK_LIBRARIES} *****")
message("***** pkg_search_module DLT_LIBRARY_DIRS = ${DLT_LIBRARY_DIRS} *****")
message("***** pkg_search_module DLT_LDFLAGS = ${DLT_LDFLAGS} *****")
message("***** pkg_search_module DLT_LDFLAGS_OTHER = ${DLT_LDFLAGS_OTHER} *****")
message("***** pkg_search_module DLT_INCLUDE_DIRS = ${DLT_INCLUDE_DIRS} *****")
Following is the output from Log library CMakeLists.txt & it looks ok.
-- Checking for one of the modules 'automotive-dlt'
***** pkg_search_module DLT_MODULE_NAME = automotive-dlt *****
***** pkg_search_module DLT_FOUND = 1 *****
***** pkg_search_module DLT_LIBRARIES = dlt;rt;pthread *****
***** pkg_search_module DLT_LINK_LIBRARIES = /home/map/third_party/lib/libdlt.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so *****
***** pkg_search_module DLT_LIBRARY_DIRS = /home/map/third_party/lib *****
***** pkg_search_module DLT_LDFLAGS = -L/home/map/third_party/lib;-ldlt;-lrt;-lpthread *****
***** pkg_search_module DLT_LDFLAGS_OTHER = *****
***** pkg_search_module DLT_INCLUDE_DIRS = /home/map/third_party/include/dlt;/home/map/third_party/include *****
-- Configuring done
After this I am building 1 application & 2 Library using above mentioned Log library but it is failing to link with following error
[100%] Linking CXX shared library libe2exf.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX shared library libe2e.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX executable execution-manager
/usr/bin/ld: cannot find -ldlt
If I install this two component (sudo apt-get install libdlt2 & sudo apt-get install libdlt-dev ) then 2 Libraries(libe2exf.so & libe2e.so) are building but failing application(execution-manager) with following error
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o): in function
ara::log::LogStream::operator<<(ara::core::Span<ara::core::internal::Byte const, 18446744073709551615ul>)':log_stream.cpp:(.text+0xbaf): undefined reference to
dlt_user_log_write_sized_utf8_string'/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o): in function
ara::log::LogStream::WithLocation(ara::core::internal::basic_string_view<char, std::char_traits<char> >, int)':log_stream.cpp:(.text+0xdc6): undefined reference to
dlt_user_log_write_sized_utf8_string'
I don't want to install libdlt2 & libdlt-dev and please let me know how to link above 1 application & 2 Library to /home/map/third_party/lib/libdlt.so;
I am using following cmake command to build. Please let me know if it is wrong.
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DARA_ENABLE_TESTS=OFF \
-DIMPORTED_LOCATION=/home/manoj/third_party,/home/manoj/third_party/lib/pkgconfig \
-DINTERFACE_INCLUDE_DIRECTORIES=/home/manoj/third_party/include \
-DINCLUDE_DIRECTORIES=/home/manoj/third_party \
-DCMAKE_MODULE_PATH=/home/manoj/third_party/share/cmake-3.16/Modules \
-DCMAKE_PREFIX_PATH=/home/manoj/third_party \
-DCMAKE_INSTALL_PREFIX=/home/manoj/third_party \
-DCMAKE_BUILD_TYPE=Release ..
Thanks in advance
As far as I see, you only need to add the link directory to your target:
target_link_directories(${PROJECT_NAME}
PUBLIC
${DLT_LIBRARY_DIRS}
)
This is because DLT_LIBRARIES
don't contain the path information about those libraries. The path information is contain in the directory variable.
You can see this in the DLT_LDFLAGS
that linking require to add the directory before linking to the library.
An even better solution would be to use DLT's imported targets if it exports one, since it would take care of all of this by itself.