本文介绍了升压蟒蛇链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加的Boost.Python为我的游戏。我写的包装我的班在脚本中使用它们。问题是,库链接到我的应用程序。我使用 cmake的构建系统。

I'm adding boost.python for my Game. I write wrappers for my classes to use them in scripts. The problem is linking that library to my app. I'm using cmake build system.

现在我有1个文件和Makefile它一个简单的应用程序:

Now I have a simple app with 1 file and makefile for it:

PYTHON = /usr/include/python2.7

BOOST_INC = /usr/include
BOOST_LIB = /usr/lib

TARGET = main

$(TARGET).so: $(TARGET).o
    g++ -shared -Wl,--export-dynamic \
    $(TARGET).o -L$(BOOST_LIB) -lboost_python \
    -L/usr/lib/python2.7/config -lpython2.7 \
    -o $(TARGET).so

$(TARGET).o: $(TARGET).cpp
    g++ -I$(PYTHON) -I$(BOOST_INC) -c -fPIC $(TARGET).cpp

和工作原理。它建立了我一个'让'文件,我可以从蟒蛇导入。

And this works. It builds a 'so' file for me which I can import from python.

现在的问题是:?如何得到这个对cmake的

Now the question: how to get this for cmake?

我在写的主 CMakeList.txt

...
find_package(Boost COMPONENTS filesystem system date_time python REQUIRED)
message("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
message("Libs of boost: " ${Boost_LIBRARIES} )

include_directories(
    ${Boost_INCLUDE_DIRS}
        ...
)

target_link_libraries(Themisto
    ${Boost_LIBRARIES}
    ...
)
...

的消息来电显示:

Include dirs of boost: /usr/include
Libs of boost: /usr/lib/libboost_filesystem-mt.a/usr/lib/libboost_system-mt.a/usr/lib/libboost_date_time-mt.a/usr/lib/libboost_python-mt.a

好了,我已经添加了简单的.cpp文件为我的项目,包括&LT的;升压/ python.hpp> 。我在编译得到一个错误:

Ok, so I've added simple .cpp-file for my project with include of <boost/python.hpp>. I get an error at compiling:

/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory

所以也没有采取一切需要的include目录。

So it doesn't take all need include directories.

第二问题:

如何组织的脚本cpp文件2步建设呢?在生成文件中我发现有 TARGET.o TARGET.so 后,如何处理,在cmake的两个命令?

How to organize 2-step building of script-cpp files? In makefile I showed there are TARGET.o and TARGET.so, how to process that 2 commands in cmake?

据我了解,最好的办法就是在那里创建子项目,做一些事情。

As I understand, the best way is to create subproject and do something there.

感谢。

推荐答案

您缺少你include目录和库在您CMakeList.txt蟒蛇。使用PythonFindLibs宏或您用于升压同一find_package策略

You are missing your include directory and libs for python in your CMakeList.txt. Use the PythonFindLibs macro or the same find_package strategy you used for Boost

find_package(Boost COMPONENTS filesystem system date_time python REQUIRED)
message("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
message("Libs of boost: " ${Boost_LIBRARIES} )

find_package(PythonLibs REQUIRED)
message("Include dirs of Python: " ${PYTHON_INCLUDE_DIRS} )
message("Libs of Python: " ${PYTHON_LIBRARIES} )

include_directories(
    ${Boost_INCLUDE_DIRS}
    ${PYTHON_INCLUDE_DIRS}  # <-------
        ...
)

target_link_libraries(Themisto
    ${Boost_LIBRARIES}
    ${PYTHON_LIBRARIES} # <------
    ...
)
...

这篇关于升压蟒蛇链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:22