gpt4 book ai didi

Boost/python.hpp is not correctly linked when using CMake and Conan(使用CMake和Conan时,Boost/python.hpp链接不正确)

转载 作者:bug小助手 更新时间:2023-10-25 20:01:49 27 4
gpt4 key购买 nike



I am trying to use conan for the very first time to try to retrieve Boost.Python and start a project using it. I have having issues that once I open my visual studio solution I get a red underline for #include <boost/python.hpp> and it will not compile.

我第一次尝试使用Conan来尝试检索Boost.Python并使用它启动一个项目。我有一些问题,一旦我打开我的Visual Studio解决方案,我会得到一个红色下划线#Include ,并且它将无法编译。


I have a following build structure,

我有一个下面的建筑结构,


src/main.cpp is the following,

SRC/main.cpp如下所示:


#include <iostream>

#include <boost/python.hpp>

using namespace boost::python;

int main()
{
std::cout << "Hello World!";
}

My CMakeLists.txt is,

我的CMakeLists.txt是,


cmake_minimum_required(VERSION 3.15)

project(myMath)

find_package(Boost)

add_executable(${PROJECT_NAME}    
src/main.cpp)

target_link_libraries(${PROJECT_NAME}    
Boost::python)

Finally my conanfile.txt is,

最后,我的conanfile.txt是,


[requires]
boost/1.83.0

[options]
boost*:without_python=False

[generators]
CMakeDeps
CMakeToolchain

Running conan install . --output-folder=build --build=missing will retrieve Boost correctly and also find Boost::python. I build my solution using,

正在运行Conan安装。--输出文件夹=Build--Build=Missing将正确检索Boost并找到Boost::Python。我使用以下工具构建我的解决方案


cmake .. -G "Visual Studio 19 2022" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake.

CMake..-G“Visual Studio 19 2022”-DCMAKE_TOOLCHAIN_FILE=CONAN_TOOLCHIN.cmake。


Looking inside the conan_toolchain.cmake I can see the following line,

查看conan_toolchain.cmake中,我可以看到下面的行,


list(PREPEND CMAKE_INCLUDE_PATH "C:/Users/Name/.conan2/p/b/boost4b77a2a85257b/p/include"

列表(前置CMAKE_INCLUDE_PATH“C:/Users/Name/.conan2/p/b/boost4b77a2a85257b/p/include”


I can verify that python.hpp exists at
C:/Users/Name/.conan2/p/b/boost4b77a2a85257b/p/include/boost/python.hpp.

我可以在C:/Users/Name/.conan2/p/b/boost4b77a2a85257b/p/include/boost/python.hpp.上验证python.hpp是否存在


From this component alone I am unsure why it is not linking.

仅从这个组件,我不确定为什么它没有链接。


From all of this I do not understand why my visual studio cannot correctly link to boost/python.hpp once I open my solution. Any help is appreciated. I am also receiving a linking error trying to find ZLIB when following the conan2 tutorial. I have followed all the steps and made sure the variables are all set from my previous question.

从这一切中,我不明白为什么一旦我打开我的解决方案,我的视觉工作室就不能正确地链接到Boost/python.hpp。如有任何帮助,我们不胜感激。我也收到了一个链接错误,试图找到ZLIB时,遵循conan2教程。我已经按照所有步骤进行了操作,并确保从上一个问题开始设置了所有变量。


The desired folder structure is,

所需的文件夹结构是,


BoostExample
- Build
- CMake
- CMake output is here (soltuion etc)
- (Build file from conan are put here)
- Src
main.cpp
- CMakeLists.txt
- conanfile.txt

enter image description here


The exact error when trying to compile from the CLI is,

尝试从CLI编译时的确切错误是,


C:/Users/Michael/.conan2/p/b/boost4b77a2a85257b/p/include\boost/python/detail/wrap_python.hpp(57,11): fatal  error C108
3: Cannot open include file: 'pyconfig.h': No such file or directory [C:\Users\Michael\Desktop\C++\BoostExample\build\C
Make\myMath.vcxproj]

When opening the solution file, a red squiggly is under the include and it will not compile there. I also receive the same problem when following the tutorial using ZLIB, however that seems to compile when using the CLI commands, but still does not link correctly.

当打开解决方案文件时,在Include下方有一个红色的曲折图标,它将不会在那里进行编译。当我使用ZLIB遵循教程时,我也收到了同样的问题,然而,当使用CLI命令时,似乎可以编译,但仍然不能正确链接。


更多回答

It is not clear if it doesn't compile because it cannot find the header (you comment it cannot correctly link). The contents of the conan_toolchain.cmake are not the most important ones, but the contents of the conan generated boost-config.cmake that should be the ones found by CMake. It might be worth to submit the above, together with the full log to github.com/conan-io/conan as a github issue.

不清楚它是否因为找不到头文件而无法编译(您注释它不能正确链接)。Conan_Toolchain.cmake的内容不是最重要的内容,但Conan生成的Boost-config.cmake的内容应该是CMake找到的内容。将上述内容连同完整的日志一起作为GitHub的问题提交到githorb.com/conan-io/conan可能是值得的。

@drodri Following the tutorial I can get it to compile and run the executable using the CLI commands, however opening the solution I still get a red underline and it is not linking to ZLIB. However in this case even using the CLI commands I still get a /python/detail/wrap_python.hpp(57,11): fatal error C108 3: Cannot open include file: 'pyconfig.h':.

@drodri按照教程,我可以使用CLI命令让它编译并运行可执行文件,但是打开解决方案时,我仍然会看到红色下划线,并且它没有链接到ZLIB。然而,在这种情况下,即使使用CLI命令,我仍然得到一个/python/Detail/WRAP_python.hpp(57,11):致命错误C108 3:无法打开包含文件:‘pyfig.h’:。

The file pyconfig.h, which is actually missed, comes from the Python, not from the Boost. I would expect Boost::python target to have appropriate dependency on the Python library. But most of examples about using Boost python aside from find_package(Boost) perform find_package(Python COMPONENTS Development) (or its alternatives).

文件pyfig.h实际上被遗漏了,它来自于Python,而不是来自Boost。我希望Boost::Python目标对Python库有适当的依赖。但是除了Find_Package(Boost)之外,大多数关于使用Boost Python的示例都执行Find_Package(Python组件开发)(或它的替代品)。

in order to use find_package I need to have the config file, where would this be retrieved from, another conan dependency?

为了使用FIND_PACKAGE,我需要有配置文件,这将从哪里检索到,另一个Conan依赖项?

优秀答案推荐

Strangely find_package(Boost) doesn't look for python, this is the case even when not using conan, you need to manually bring in python yourself:

奇怪的是,FIND_PACKAGE(Boost)并不查找Python,即使在不使用Conan的情况下也是如此,您需要自己手动引入Python:


cmake_minimum_required(VERSION 3.15)

project(myMath)

find_package(Boost)
find_package(Python3 COMPONENTS Development)

add_executable(${PROJECT_NAME}
main.cpp)

target_link_libraries(${PROJECT_NAME}
Boost::python Boost::python Python3::Python)

更多回答

Interesting, but for find_package to work I need the associated config files for Python3. Where can I find these if this is not retrieved from conan?

这很有趣,但要让findPackage正常工作,我需要与Python3相关联的配置文件。如果这不是从柯南那里取回的,我在哪里能找到这些?

They're built into cmake cmake.org/cmake/help/latest/module/FindPython3.html, it should just work, i didn't have to do any additional configuration to get this example to build

它们被内置到cmake cmake.org/cmake/help/latest/module/FindPython3.html,中,它应该可以工作,我不需要做任何额外的配置就可以构建这个例子

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com