I am trying to understand how to manage multiple projects with cmake and I used https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file as a start I would like to create a project that can include the lib Foo (from the link)
The example is compiled correctly and I tried to add a project to the FooBar directory called "app"
FooBar/app/
├── CMakeLists.txt
└── src
├── app.cpp
CMakeLists.txt
project(app)
find_package(FooBar)
add_executable(app
src/app.cpp)
target_link_libraries(app ${FOOBAR_LIBRARIES})
app.cpp
#include<foo/foo.h>
int main(int argc, char** argv){
foo();
return 0;
}
The error I received is
app.cpp:(.text+0x10): undefined reference to `foo()'
It seems that the find_package and the import of the header foo.h work fine. but for some reason, the library seems doesn't seem to be linked.
I tried to just append the CMakeLists.txt of the app project to the FooBar CMakelists.txt with add_subdirectory(app)
or to run the cmake
and make
cmd in a completely different directory and both have the same result
I was expecting it to work within the same CMakelists or in another directory with the environment variable export CMAKE_PREFIX_PATH=/path/to/FooBar/build:${CMAKE_PREFIX_PATH}
Anyone would have an idea about what is wrong in my case? Thanks