I have the following layout which contains multiple projects separate directories (It's a CPP project):
Demo
├── Lib
│ ├── CMakeLists.txt
│ ├── inc
│ └── lib
│ ├── crypto_ic.so
│ └── crypto.so
├── Proj1
│ ├── App1
│ └── CMakeLists.txt
└── Proj2
├── App2
└── CMakeLists.txt
I created one separate third-party-lib.bb
file to install crypto_ic.so
,crypto.so
into /usr/lib/
in the target using do_install_append
.
All applications are depending on third-party libraries. There are no parent cmake for proj1,proj2 those are independent projects built by *.bb
files using yocto.
Now I need to integrate the third party library for all the applications. I created one interface library for the third party headers and using find_package
I am able to find the headers and the compilation is working fine.
CMakeLists.txt(Lib)
cmake_minimum_required(VERSION 3.8)
project(crypto VERSION 1.0.0 LANGUAGES CXX)
include(GNUInstallDirs)
find_package(Boost REQUIRED)
add_library(crypto INTERFACE)
target_link_libraries(crypto INTERFACE
Boost::boost
)
target_include_directories(crypto INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/inc/>
$<INSTALL_INTERFACE:include>
)
# Create and Install *-config.cmake,*-version.cmake files
# Install exported targets, i.e. *-targets.cmake
# Install header files
CMakeLists.txt(Proj1)
cmake_minimum_required(VERSION 3.8)
project(App1 VERSION 1.0.0 LANGUAGES CXX)
include(GNUInstallDirs)
find_package(crypto REQUIRED)
add_executable(run Run.cpp)
target_link_libraries(run PUBLIC
crypto
)
But the problem is while linking I am getting a linker error.
Run.cpp: undefined reference to 'Intialize(std::string hashName)'
Initialize
function definition is available in the shared library.
Any thoughts on how to fix the issue and how to remove the hardcode path to the library in CMake?.
I am new to CMake and not sure this is a good approach to follow, only reason I created the Interface library is to install the headers in target and find the package. I can modify it if there are some better solutions?
Edit:
I found the issue in the cmake, I didn't link the shared library files (*.so
) in the application that's the reason I am getting the linker error. But I am not getting how to link that from the target?