gpt4 book ai didi

用于 swig : how enable c++11 的 Python 和 c++11

转载 作者:行者123 更新时间:2023-11-28 17:28:36 25 4
gpt4 key购买 nike

我正在尝试使用 swig 将共享库与 python 一起使用。我对 C++ 的实验并不多,但我已经用一个简单的对象(在 C++ 中)进行了第一次测试,并且效果很好。

现在我尝试让它与已经在 Linux(和 Windows)下编译的更大项目一起工作。但我无法让它发挥作用。

这是我尝试过的:

我的 CMakeLists for Swig :

project(elecswig)

include_directories(${COREALPI_DIR}/include)
include_directories(/usr/include/c++/4.9)

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})

set_source_files_properties(src/elec.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(src/elec.i PROPERTIES SWIG_FLAGS "-includeall")

link_directories(${COREALPI_LIBRARY})

swig_add_module(elecswig python src/elec.i)

swig_link_libraries(elecswig
${PYTHON_LIBRARIES}
elec
)

还有我的 elec.i for Swig,它用命名空间调用 .h:

#define __linux__ 1
#define __GNUC__ 4

%module elecswig
%{
#include "ca/elec/model/modelvoltagedrop.h"
%}

%include "ca/elec/model/modelvoltagedrop.h"

当我尝试编译以获取我的 Python Lybrary 时,出现以下错误:

/usr/include/c++/4.9/bits/c++0x_warning.h:32: Error: CPP #error "This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.". Use the -cpperraswarn option to continue swig processing.
/usr/include/c++/4.9/cstring:41: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/string:38: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/stringfwd.h:39: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/memoryfwd.h:48: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/stl_algobase.h:59: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/functexcept.h:39: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/cpp_type_traits.h:37: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/ext/type_traits.h:34: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/move.h:33: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/concept_check.h:35: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/stl_iterator_base_types.h:64: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/cwchar:41: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/allocator.h:46: Error: Unable to find 'bits/c++allocator.h'
/usr/include/c++/4.9/bits/localefwd.h:39: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/bits/localefwd.h:40: Error: Unable to find 'bits/c++locale.h'
/usr/include/c++/4.9/iosfwd:38: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/cctype:41: Error: Unable to find 'bits/c++config.h'
[...]
/usr/include/c++/4.9/cstdlib:41: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/utility:68: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/ctime:41: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/ctime:42: Error: Unable to find 'time.h'
/usr/include/c++/4.9/iomanip:38: Error: Unable to find 'bits/c++config.h'
/usr/include/c++/4.9/numeric:60: Error: Unable to find 'bits/c++config.h'
elecswig/CMakeFiles/_elecswig.dir/build.make:53: recipe for target 'elecswig/elecPYTHON_wrap.cxx' failed
make[2]: *** [elecswig/elecPYTHON_wrap.cxx] Error 1
CMakeFiles/Makefile2:75: recipe for target 'elecswig/CMakeFiles/_elecswig.dir/all' failed
make[1]: *** [elecswig/CMakeFiles/_elecswig.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2

他好像找不到很多files.h但是我大部分都是c++11错误

我试图在 CMake 中设置标志,但似乎没有任何改变。

如果你能帮助我,好吗?

如果需要,我可以提供更多信息。

谢谢

最佳答案

经过几个小时的测试,我找到了它不起作用的原因。在 CMakeLists 中:

set_source_files_properties(src/elec.i PROPERTIES SWIG_FLAGS "-includeall")

包括所有库和依赖项,无论如何编译器使用。如果你有 2 个版本的 libstdc++ 和 gcc/g++,他似乎找不到好的库来链接/使用。

如果我删除它,CMake 会完成这项工作。我不再有 unable to findc++11 问题。

我必须使用 g++-5 来让它工作(4.9 似乎缺少 c++11 的一些功能)并添加好的命名空间和包含。

现在我可以使用 Python 访问我的共享库。

关于用于 swig : how enable c++11 的 Python 和 c++11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36456689/

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