0

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
goodman
  • 424
  • 8
  • 24
  • How about just using [find_package with hint](https://stackoverflow.com/a/49816516/4123703) for this library? It should work but I'm not sure if it's a good practice. – Louis Go Jul 29 '21 at 03:34
  • 1
    I checked the example link. In my case, I need to install headers and `*.so` files are not part of the host machine rootfs it will be installed in the Image which created by yocto. – goodman Jul 29 '21 at 03:54
  • "I am getting a linker error saying .." - No, do not *describe* the error message. Instead, show it (add to the question post). Also add to the post the code which causes it. It could be that you incorrectly **use** your library, or forget to add `find_dependency(Boost)` into your `*-config.cmake` file. – Tsyvarev Jul 29 '21 at 06:55
  • updated the question with the changes.`Boost` is working fine,No issues in the `*-config.cmake` – goodman Jul 29 '21 at 07:44
  • Finally, I fixed this issue. I installed the library and its config,version Cmake using bb file.In the app I find the library using `find_library`.Its working now, – goodman Aug 10 '21 at 08:20

0 Answers0