1

I have a pre-compiled dependency library A which has only include/ and lib/

A was built with system library B which was installed in /usr/local/include/B/ and /usr/local/lib/B

But on my building system doesn't have library B and do not allow me to modify the system (no privilege).

I downloaded B and put B_include in local project C's include directory and B_lib in C's lib directory.

I tried in CMakeList.txt of local project:

include_directories(
    C_INCLUDE_DIR
    B_INCLUDE_DIR
)

link_directories(
    C_LIB_DIR
    B_LIB_DIR
)

But when compile C against library A, A's include can not find the local header file B_INCLUDE_DIR. Does anyone know how to force CMake to find the local library file other than directly navigate into system include and lib directories?

To sum up, can I tell CMake to force a pre-compiled library to use local include file?

rain cheng
  • 71
  • 1
  • 5
  • 1
    "*But it doesn't work*"... This is a pretty vague problem description. Could you please describe *how* it doesn't work, including any relevant error messages or undesired behaviors. Also, it looks like this [question](https://stackoverflow.com/q/24570916/3987854) addresses something very similar to what you're asking. Specifically, `link_directories()` doesn't actually link the libraries, it only provides an additional path to the linker for library searching. – Kevin May 28 '20 at 03:16

1 Answers1

0

Just solved the problem. It turn out to be my own mistake. Thanks to squareskittles's comments.

the following CMakeList commends will do the work nicely:

include_directories(
    C_INCLUDE_DIR
    B_INCLUDE_DIR
)

link_directories(
    C_LIB_DIR
    B_LIB_DIR
)

rosbuild_add_executable(your_executable src/your_source_file.cpp)

TARGET_LINK_LIBRARIES(your_executable lib1.so lib2.so lib3.so ...)
rain cheng
  • 71
  • 1
  • 5