I want to handle the dependencies of a C++/cmake/gcc
project in Linux using conan, and build an ImGui C++ demo as shown here: using imgui by Elias Daler
I have used conan to handle Boost
dependencies successfully, but with ImGui-SFML I am having a linking error.
My conanfile.txt
has the following instructions:
[requires]
imgui-sfml/2.1@bincrafters/stable
[imports]
bin, *.so -> ./bin
lib, *.a -> ./lib
[generators]
cmake_find_package
cmake_paths
cmake
And I added these lines to my CMakeLists.txt
to work with conan:
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
link_directories(${CONAN_LIB_DIRS})
target_link_libraries(my_project ${CONAN_LIBS})
Then, inside build/
I run the following command to build the library and install the dependencies:
conan install .. --build imgui-sfml
So far so good with conan, the libImGui-SFML.a
is generated (it is also copied to build/lib
because of the [imports]
, though I think the copy shouldn't be required since I'm adding the link_directories()
instruction).
Then, I generate the makefiles
cmake ..
Finally, when I try to build the project
cmake --build ./
I get these linking errors:
/usr/bin/ld: cannot find -lImGui-SFML
/usr/bin/ld: cannot find -lopenal
/usr/bin/ld: cannot find -lFLAC++
/usr/bin/ld: cannot find -lFLAC
The libs generated by conan are static:
libFLAC.a
libFLAC++.a
libfreetype.a
libImGui-SFML.a
libogg.a
libopenal.a
This post looks related, but didn't work for ImGui: Installing gtest with conan
Is the program looking for shared libraries?
Am I missing some configuration in the conanfile.txt
or in the CMakeLists.txt
file?
Edit:
Conan version 1.25.2
According to this reported issue, this solution for a similar question, and conan's basic setup documentation, in this case the CMakeLists.txt
should include: adding the argument TARGET
in the setup, and the call to conan_target_link_libraries
instead of the usual target_link_libraries
, as follows:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
conan_target_link_libraries(${PROJECT_NAME})
So the conanfile.txt
just needs these instructions:
[requires]
imgui-sfml/2.1@bincrafters/stable
[generators]
cmake