[英]How to use conan to handle ImGui-SFML dependency in a cmake gcc project in Linux?
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我想使用 conan 处理 Linux 中的
C++/cmake/gcc
项目的依赖项,并构建一个 ImGui C++ 演示,如下所示: using imgui by Elias Daler
I have used conan to handle Boost
dependencies successfully, but with ImGui-SFML I am having a linking error.我已经使用 conan 成功处理了
Boost
依赖项,但是使用 ImGui-SFML 我遇到了链接错误。
My conanfile.txt
has the following instructions:我的
conanfile.txt
有以下说明:
[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:我将这些行添加到我的
CMakeLists.txt
以使用柯南:
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:然后,在
build/
中,我运行以下命令来构建库并安装依赖项:
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).到目前为止,柯南很好,生成了
libImGui-SFML.a
(由于[imports]
,它也被复制到build/lib
中,尽管我认为不需要复制,因为我正在添加link_directories()
操作说明)。
Then, I generate the makefiles然后,我生成makefile
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:柯南生成的库是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这篇文章看起来很相关,但不适用于 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?我是否缺少
conanfile.txt
或CMakeLists.txt
文件中的某些配置?
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:根据这个报告的问题,这个类似问题的解决方案,以及柯南的基本设置文档,在这种情况下,
CMakeLists.txt
应该包括:在设置中添加参数TARGET
,以及调用conan_target_link_libraries
而不是通常的target_link_libraries
,如下所示:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
conan_target_link_libraries(${PROJECT_NAME})
So the conanfile.txt
just needs these instructions:所以
conanfile.txt
只需要这些说明:
[requires]
imgui-sfml/2.1@bincrafters/stable
[generators]
cmake
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.