CMake: Combining two projects in CMakeLists.txt?

时间:2018-03-25 19:52:03

标签: c++ c cmake

I have the following structure of my projects:


Project1/src/samples/*.cpp files

Project1/src/Project2/examples/*.cc and *.h files

Project1/src/Project2/lib/*.c , *.h , *.o and a .la files

The .la file is created using the *.c source files in the lib folder of Project2 using libtool.

I need to link the .la file in one of the cpp files present in the Project1/src/samples/.

I have already tried the following in CmakeLists.txt present in Project1/src/samples: add_executable(source_file source_file.cpp) target_link_library(source_file ${LOCATION_OF_.LA_FILE})

CMakeLists.txt is present in

  1. Project1/
  2. Project1/src
  3. Project1/src/samples
  4. Project1/src/Project2/
  5. Project1/src/Project2/examples
  6. Project1/src/Project2/lib

Every time I make the Project1's source_file I get the following linker error "Undefined reference to fun()" where, fun() is defined in one of the c files present in Project1/src/Project2/lib/.

Any ideas what is the problem and how to link the .la of Project2 in Project1. Or is there a way I can include the *.c files from Project2/lib's folder in the CMakeLists.txt of Project1's samples folder?

0 个答案:

没有答案