1

I've created custom shared object with one function inside - void hello(); which only prints "hello". I'm now trying to use the SO in another project, but I can't use it (more likely - I don't know how to)

The test_lib.so file is at the same as my main.c.

I'm trying to include the lib in my CMakeLists.txt as following:

cmake_minimum_required(VERSION 3.12)
project(test2 VERSION 1.0.0)

find_library(MYLIB test_lib.so)

add_executable(test main.c)

target_link_libraries(test MYLIB)

But when I try to use hello(); on my main.c I'm getting the error:

undefined reference to `hello'
  • 1
    Please see the responses to the following question for ways to include an external library (e.g. `.so`) in your CMake project: [CMake link to external library](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) – Kevin Jul 13 '20 at 17:01

1 Answers1

1

Just list the actual library file in target_link_libraries:

target_link_libraries(test test_lib.so)

You could also add the library as an IMPORTED library target, and set its IMPORTED_LOCATION property.

Then you could list it in target_link_libraries as any other library target.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621