0

I have two cmake projects:

BiosPatcher\CommonBase\
BiosPatcher\Bios\

First one builds a library and has ./include folder with headers. How to build second project library(or executable) which depends on first library ./include for compilation and libCommonBase.dll for execution(in case of executable file building).

I've included header files like that

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../CommonBase/include)

And it works.

And I link library like that:

target_link_libraries (Bios libCommonBase)

But I get error message:

c:\Users\Sakhno\workspace\BiosPatcher\Bios\build>make
[ 16%] Linking CXX shared library libBios.dll
C:/mingw-w64/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -llibCommonBase
collect2.exe: error: ld returned 1 exit status

I think i need somehow specify folder to look for the library but i don't know how.

Vyacheslav
  • 3,134
  • 8
  • 28
  • 42
  • at least I need how to include headers correctly – Vyacheslav Jun 14 '16 at 18:38
  • 2
    What is wrong with using command [include_directories](https://cmake.org/cmake/help/v3.0/command/include_directories.html) for setting up include directories and [target_link_libraries](https://cmake.org/cmake/help/v3.0/command/target_link_libraries.html) for linking with library? – Tsyvarev Jun 14 '16 at 22:57
  • Sharing your research helps everyone. Please tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! Also see [how to ask](http://stackoverflow.com/questions/how-to-ask) – Florian Jun 15 '16 at 07:58
  • Thanks for the clarification. If you are not adding the other project via [`add_subdirectory()`](https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html), then would one of the following questions help? [Making cmake library accessible by other cmake packages automatically](http://stackoverflow.com/questions/33462209) (searching the other project) or [How to instruct CMake to use the build architecture compiler?](http://stackoverflow.com/questions/36173840) (injecting the others project's build path from the outside). – Florian Jun 15 '16 at 16:57

1 Answers1

0

I was able to build Bios project which depends on CommonBase project target library by adding following lines.

set(COMMON_BASE_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../CommonBase)

...
include_directories(${COMMON_BASE_PROJECT_DIR}/include)

...
target_link_libraries (Bios ${COMMON_BASE_PROJECT_DIR}/build/libCommonBase.dll)
Vyacheslav
  • 3,134
  • 8
  • 28
  • 42
  • To get code of how to build dependent project as dependency see question: http://stackoverflow.com/questions/37838786/how-to-not-make-install-step-when-building-external-project-with-cmake – Vyacheslav Jun 16 '16 at 14:30