0

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
Lejuanjowski
  • 139
  • 1
  • 2
  • 6
  • I tried to reproduce the issue and looks like setup is correct. Could you provide your conan settings/version and maybe push your small project to github that reproduces the issue? – ymochurad Aug 07 '20 at 09:04
  • I edited the question to include the conan version (1.25.2), however, I managed to find a solution so I posted it as an answer. Nevertheless, if you're still interested, [here](https://github.com/spjuanjoc/game_project_cpp) you may find my project. – Lejuanjowski Aug 08 '20 at 01:55

1 Answers1

0

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
Lejuanjowski
  • 139
  • 1
  • 2
  • 6