Quantcast

C++11 with CMake

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

C++11 with CMake

Estrada Matthieu
Hello,

I'm trying to get swig works with my c++ module and python. For that I use CMake and GCC.

I've currently other projects with CMake files who works on c++14. And I encounter errors for SWIG module:

/usr/include/c++/5/bits/c++0x_warning.h:32: Error: CPP #error "This file requires compiler and library support \
for the ISO C++ 2011 standard. This support must be enabled \
with the -std=c++11 or -std=gnu++11 compiler options.". Use the -cpperraswarn option to continue swig processing.


But I've define this in my CMake with "-std=c++14", so I don't understand why swig warns about that. Here is my files:

CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

PROJECT(coreswig CXX)

INCLUDE_DIRECTORIES(../../corealpi/include/ca/)
INCLUDE_DIRECTORIES(/usr/include/c++/5)
INCLUDE_DIRECTORIES(/usr/include)
INCLUDE_DIRECTORIES(/usr/lib/gcc/x86_64-linux-gnu/5/include)
INCLUDE_DIRECTORIES(/usr/include/x86_64-linux-gnu/c++/5)

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

#SET(CMAKE_SWIG_FLAGS "")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES SWIG_FLAGS "-includeall")
ADD_SUBDIRECTORY(../../corealpi/platform/cmake/core ${CMAKE_BINARY_DIR}/core)

SWIG_ADD_MODULE(coreswig python coreswig.i)
SWIG_LINK_LIBRARIES(coreswig core ${PYTHON_LIBRARIES})

coreswig.i
%define __linux__ 1
%enddef
%define __GNUC__ 4
%enddef

%module coreswig
%{
    #include "../../corealpi/core/extra/src/platform.h"
    #include "../../corealpi/include/ca/core.h"
%} 
   
%include "../../corealpi/core/extra/src/platform.h"
%include "../../corealpi/include/ca/core.h"

I notice that if I remove "SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES SWIG_FLAGS "-includeall")", ERROR disappear but no longer see macros define in .h...

How I can solve this problem ?

I also noticed that when I add .h, it seems I've to redefined each MACROS... In fact I have a little trouble understanding what to put or not in the file coreswig.i.





------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C++11 with CMake

William S Fulton


On 8 March 2017 at 10:00, Estrada Matthieu <[hidden email]> wrote:
Hello,

I'm trying to get swig works with my c++ module and python. For that I use CMake and GCC.

I've currently other projects with CMake files who works on c++14. And I encounter errors for SWIG module:

/usr/include/c++/5/bits/c++0x_warning.h:32: Error: CPP #error "This file requires compiler and library support \
for the ISO C++ 2011 standard. This support must be enabled \
with the -std=c++11 or -std=gnu++11 compiler options.". Use the -cpperraswarn option to continue swig processing.


But I've define this in my CMake with "-std=c++14", so I don't understand why swig warns about that. Here is my files:

CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

PROJECT(coreswig CXX)

INCLUDE_DIRECTORIES(../../corealpi/include/ca/)
INCLUDE_DIRECTORIES(/usr/include/c++/5)
INCLUDE_DIRECTORIES(/usr/include)
INCLUDE_DIRECTORIES(/usr/lib/gcc/x86_64-linux-gnu/5/include)
INCLUDE_DIRECTORIES(/usr/include/x86_64-linux-gnu/c++/5)

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

#SET(CMAKE_SWIG_FLAGS "")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES SWIG_FLAGS "-includeall")
ADD_SUBDIRECTORY(../../corealpi/platform/cmake/core ${CMAKE_BINARY_DIR}/core)

SWIG_ADD_MODULE(coreswig python coreswig.i)
SWIG_LINK_LIBRARIES(coreswig core ${PYTHON_LIBRARIES})

coreswig.i
%define __linux__ 1
%enddef
%define __GNUC__ 4
%enddef

%module coreswig
%{
    #include "../../corealpi/core/extra/src/platform.h"
    #include "../../corealpi/include/ca/core.h"
%} 
   
%include "../../corealpi/core/extra/src/platform.h"
%include "../../corealpi/include/ca/core.h"

I notice that if I remove "SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES SWIG_FLAGS "-includeall")", ERROR disappear but no longer see macros define in .h...

How I can solve this problem ?

I also noticed that when I add .h, it seems I've to redefined each MACROS... In fact I have a little trouble understanding what to put or not in the file coreswig.i.



Use the compiler's preprocessor and SWIG's preprocessor and look at the actual headers to see what macros you need to define/undefine. BTW, including platform specific headers and using -includeall usually causes problems as you end up wrapping too much low level junk. You are usually better off carefully selecting the headers that provide the API you need and then wrap those.

William


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: C++11 with CMake

Estrada Matthieu
Hello William,

I've solved my problem before your answer. Like you say, I removed "includeall" flags and define my MACROS in my ".i" file. By including my .h after all is working good.

Here is what I add to my .i file:

%define __linux__ 1 %enddef
%define NDEBUG 1 %enddef
%define ELEC_API %enddef

%include "stdint.i" // For typedef

Thanks for help.

Le 17/03/2017 à 20:00, William S Fulton a écrit :


On 8 March 2017 at 10:00, Estrada Matthieu <[hidden email]> wrote:
Hello,

I'm trying to get swig works with my c++ module and python. For that I use CMake and GCC.

I've currently other projects with CMake files who works on c++14. And I encounter errors for SWIG module:

/usr/include/c++/5/bits/c++0x_warning.h:32: Error: CPP #error "This file requires compiler and library support \
for the ISO C++ 2011 standard. This support must be enabled \
with the -std=c++11 or -std=gnu++11 compiler options.". Use the -cpperraswarn option to continue swig processing.


But I've define this in my CMake with "-std=c++14", so I don't understand why swig warns about that. Here is my files:

CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

PROJECT(coreswig CXX)

INCLUDE_DIRECTORIES(../../corealpi/include/ca/)
INCLUDE_DIRECTORIES(/usr/include/c++/5)
INCLUDE_DIRECTORIES(/usr/include)
INCLUDE_DIRECTORIES(/usr/lib/gcc/x86_64-linux-gnu/5/include)
INCLUDE_DIRECTORIES(/usr/include/x86_64-linux-gnu/c++/5)

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

#SET(CMAKE_SWIG_FLAGS "")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES SWIG_FLAGS "-includeall")
ADD_SUBDIRECTORY(../../corealpi/platform/cmake/core ${CMAKE_BINARY_DIR}/core)

SWIG_ADD_MODULE(coreswig python coreswig.i)
SWIG_LINK_LIBRARIES(coreswig core ${PYTHON_LIBRARIES})

coreswig.i
%define __linux__ 1
%enddef
%define __GNUC__ 4
%enddef

%module coreswig
%{
    #include "../../corealpi/core/extra/src/platform.h"
    #include "../../corealpi/include/ca/core.h"
%} 
   
%include "../../corealpi/core/extra/src/platform.h"
%include "../../corealpi/include/ca/core.h"

I notice that if I remove "SET_SOURCE_FILES_PROPERTIES(coreswig.i PROPERTIES SWIG_FLAGS "-includeall")", ERROR disappear but no longer see macros define in .h...

How I can solve this problem ?

I also noticed that when I add .h, it seems I've to redefined each MACROS... In fact I have a little trouble understanding what to put or not in the file coreswig.i.



Use the compiler's preprocessor and SWIG's preprocessor and look at the actual headers to see what macros you need to define/undefine. BTW, including platform specific headers and using -includeall usually causes problems as you end up wrapping too much low level junk. You are usually better off carefully selecting the headers that provide the API you need and then wrap those.

William



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...