Ich versuche Swig zu verwenden mit shared library mit Python. Ich bin nicht sehr mit C++ experimentiert, aber ich habe einen ersten Test mit einem einfachen Objekt (in C++) gemacht und das funktioniert gut.Python und C++ 11 für swig: wie aktivieren C++ 11
Jetzt versuche ich, es mit einem größeren Projekt arbeiten, die bereits unter Linux (und Windows) kompilieren. Aber ich kann es nicht funktionieren lassen. Hier
ist das, was ich versuche haben:
Mein CMakeLists für 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
)
Und mein elec.i für Swig, die eine .h mit Namespace nennen:
#define __linux__ 1
#define __GNUC__ 4
%module elecswig
%{
#include "ca/elec/model/modelvoltagedrop.h"
%}
%include "ca/elec/model/modelvoltagedrop.h"
Und wenn ich versuche, zu kompilieren, um meine Python Lybrary zu bekommen, habe ich den folgenden Fehler:
/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
Es scheint, dass er nicht viele files.h finden kann, aber ich habe meistens den C++ 11 Fehler.
Ich habe versucht, Flags in CMake zu setzen, aber es scheint nichts zu ändern.
Wenn Sie mir bitte helfen können?
Ich kann bei Bedarf weitere Informationen zur Verfügung stellen.
Dank
Etwas ist seltsam mit Ihrem Compiler/cmake Setup, wenn Sie 'include_directories (/ usr/include/C++/4.9)' explizit schreiben müssen. – Flexo
Ich kann jedoch nicht Ihr Problem reproduzieren, ich habe fast eine identische CMake-Datei als die notierte Änderung, die funktioniert. Ich denke, dass Ihr Compiler selbst auf eine seltsame Art und Weise gebrochen sein kann, wenn die anderen Fehler auftreten. – Flexo
Das Seltsame ist, dass ich dieses Projekt (mit C++ 11 Flagge) kompilieren kann, ohne swig zu benutzen ... also warum, wenn ich swig benutze, erzähle er mir das. Ich habe eine andere Maschine versucht, und ich bekomme den gleichen Fehler. – Algorys