繁体   English   中英

提升python链接

[英]Boost python linking

我正在为我的游戏添加boost.python。 我为我的类编写包装器以在脚本中使用它们。 问题是将该库链接到我的应用程序。 我正在使用cmake构建系统。

现在我有一个简单的应用程序,包含1个文件和makefile:

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

这很有效。 它为我构建一个'so'文件,我可以从python导入。

现在的问题是:如何为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}
    ...
)
...

message调用显示:

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文件,其中包含<boost/python.hpp> 我在编译时遇到错误:

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

所以它不需要包含目录。

第二个问题:

如何组织script-cpp文件的两步构建? 在makefile中,我展示了TARGET.oTARGET.so ,如何处理cmake中的2个命令?

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

谢谢。

你在CMakeList.txt中缺少你的include目录和python的libs。 使用PythonFindLibs宏或用于Boost的相同find_package策略

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} # <------
    ...
)
...

暂无
暂无

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

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