Swig的Python和C ++ 11:如何启用C ++ 11

算法

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

现在,我尝试使其与已经在Linux(和Windows)下编译的更大项目一起使用。但是我不能使它工作。

这是我尝试过的:

我的Swig CMakeLists:

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
)

还有我给Swig的elec.i,它使用命名空间调用.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

看来他找不到很多file.h,但是我大多数都遇到了c ++ 11错误。

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

你能帮我吗?

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

谢谢

算法

经过数小时的测试,我找到了无法运行的原因。在CMakeLists中:

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

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

如果我删除它,CMake会完成这项工作。我没有更多的unable to find还是c++11问题。

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在CLion中启用C ++ 11?

来自分类常见问题

如何在gcc中启用C ++ 11?

来自分类Dev

如何在Kdevelop中启用c ++ 11

来自分类Dev

如何在Linux中启用c ++ 11

来自分类Dev

如何在Codelite中启用C ++ 11功能

来自分类常见问题

如何在Qt Creator中启用C ++ 11?

来自分类Dev

如何在Eclipse Neon中启用C ++ 11语法?

来自分类Dev

如何在Eclipse Luna中启用c ++ 11?

来自分类Dev

在Visual Studio 2013上启用c ++ 11

来自分类Dev

如何在Dev C ++ IDE中启用C ++ 11或C ++ 14

来自分类Dev

Loki和C ++ 11

来自分类Dev

从cmake启用VS 2013中的C ++ 11支持

来自分类Dev

需要在代码块中启用C ++ 11

来自分类Dev

从cmake启用VS 2013中的C ++ 11支持

来自分类Dev

在Eclipse Juno ADT中启用C ++ 11符号解析

来自分类Dev

如何制作C ++ 0x / 11和非C ++ 0x / 11的标头?

来自分类Dev

C ++ 11:如何理解函数移动

来自分类Dev

c ++ 11如何插入简单的内存屏障?

来自分类Dev

C ++如何识别SIGNAL 11错误位置

来自分类Dev

如何使用C ++ 11的最小gc支持

来自分类Dev

如何判断库是使用C ++ 11编译的

来自分类Dev

如何设置Netbeans使用C ++ 11?

来自分类Dev

C ++ 11:如何使用<random>设置种子

来自分类Dev

thread :: detach()在C ++ 11中如何工作?

来自分类Dev

C ++ 11,如何在#if中使用const

来自分类Dev

如何使用C ++ 11的最小gc支持

来自分类Dev

如何在g ++中使用C ++ 11?

来自分类Dev

如何禁用gcc警告“ cc1:警告:命令行选项'-std = c ++ 11'对C ++ / ObjC ++有效,但对C无效(默认启用)”

来自分类Dev

C ++ 11向后兼容