简体   繁体   English

Boost python不断链接python27库

[英]boost python keeps linking python27 library

Since days I am trying to get started with boost python on windows instead of my raspberry pi and I am facing issues with boost (or some of its dependencies) insisting on linking against python27.lib instead of python36.lib (I am using Python 3.6) 由于几天我想开始使用升压Windows上的Python,而不是我的树莓派,我面临着提升(或它的一些依赖)关于对链接坚持问题python27.lib代替python36.lib (我使用Python 3.6 )

On my raspberry pi I was using the bundled python which happened to be 2.X and linked against boost_python. 在我的树莓派上,我正在使用捆绑的python,它刚好是2.X并与boost_python链接。 Now on windows I am linking against boost_python3. 现在在Windows上,我链接到boost_python3。 I checked all my include paths in CMake and they all point to the 3.6 python path. 我在CMake中检查了所有包含路径,它们都指向3.6 python路径。 I even renamed all paths on my system that contain python (one standalone 2.7 and one in cygwin) in a different version (I renamed cygwin folder to cygwin2 and deleted the standalone python 2.7 folder). 我什至在系统上重命名了包含python(一个独立的2.7和cygwin中的一个)的所有路径的其他版本(我将cygwin文件夹重命名为cygwin2并删除了独立的python 2.7文件夹)。 It still wants that library... 它仍然想要那个图书馆...

In my program I have one single #include related to python and that's a #include <boost/python.hpp> . 在我的节目,我有一个单一#include与蟒蛇,这是一个#include <boost/python.hpp> I followed that include in visual studio and it leads me to the python.hpp in the boost directory that I have specified in CMake, so that resolution is working. 我遵循了Visual Studio中的include,它将我带到我在CMake中指定的boost目录中的python.hpp,这样分辨率就可以了。 Inside boost/python.hpp eventually you get to wrap_python.hpp which includes the python headers. boost/python.hpp内部,最终您将进入wrap_python.hpp ,其中包含python标头。 I also followed these in Visual Studio and it leads me to the files in the Python 3.6 folder. 我在Visual Studio中也遵循了这些规则,它引导我进入Python 3.6文件夹中的文件。

Adding a comment to that include (removing it) makes the program compile fine, so I did not accidentally add it in CMake as a library. 在包含(删除)的注释中添加(使之删除)可使程序正常编译,因此我没有意外地将其作为库添加到CMake中。 It has to be some #pragma comment somewhere. 在某处必须有一些#pragma comment

So to sum up: 所以总结一下:

  • There is no #include <Python.h> in my code 我的代码中没有#include <Python.h>
  • I only include boost/python.hpp once 我只包含一次boost/python.hpp
  • Uncommenting that include "fixes" it 取消注释,包括“修复”它
  • I am using python 3.6 everywhere 我到处都在使用python 3.6
  • I disabled auto linking for boost in CMake with add_definitions(... -DBOOST_ALL_NO_LIB -DBOOST_PYTHON_DEBUG) 我用add_definitions(... -DBOOST_ALL_NO_LIB -DBOOST_PYTHON_DEBUG)禁用了自动链接以增强CMake

My question(s): 我的问题:

  • Who or what could be causing this? 是谁或什么原因造成的? Does boost directly link the python libraries? boost是否直接链接python库?
  • Is there a possibility in Visual Studio to somehow highlight all the files/lines where the preprocessor encounters a #pragma so I can track it down (because I am pretty sure it somehow somewhere gets a 2.7 python I am not aware of...) 在Visual Studio中是否有可能以某种方式突出显示预处理器遇到#pragma所有文件/行,因此我可以对其进行跟踪(因为我很确定它以某种方式会得到一个我不知道的2.7 python ...)

I just went through this Boost will check for PY_MAJOR_VERSION to determine which libs to link with. 我刚刚经历了这个 Boost,它将检查PY_MAJOR_VERSION以确定要链接的库。 So in c++ > General > Additional Include Directories , add your python include path so boost can see that PY_MAJOR_VERSION == 3 . 因此,在c++ > General > Additional Include Directories ,添加python include路径,以便boost可以看到PY_MAJOR_VERSION == 3 If it doesn't it will pull the 2.x libs in by default. 如果不是,它将默认拉入2.x库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM