Integration between C++ cmake and python (and google tests)

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

Integration between C++ cmake and python (and google tests)

Andrea Bianco
Dear All,

first of all, hello to everyone. I like a lot the idea behind Swig and thanks to the developer of this fantastic project.
I am trying to produce some python swig interfaces from a C++ project using Cmake. I have a problem that I was not able to solve, even googling around quite a lot :)

my directory structure is:
——
cmake/Modules/
ext/
include/
pythonSwig/
src/
test/
CMakeLists.txt

the CMakeLists.txt file is pasted here http://pastebin.com/4fhhfgbF 

and the DMMaker.i file under the directory pythonSwig/ is 

%module DMMaker
%include "std_string.i"
%{
#include "DMMaker.h"
%}
%include "DMMaker.h"
everything compiles, but when I try to import the DMMaker class (defined in DMMaker.h, that include  LpList.h):

>>> import DMMaker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "DMMaker.py", line 28, in <module>
    _DMMaker = swig_import_helper()
  File "DMMaker.py", line 24, in swig_import_helper
    _mod = imp.load_module('_DMMaker', fp, pathname, description)
ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList

I also tried to add the line

set_source_files_properties(${SWIG_PROJECTS_DIR}/DMMaker.i PROPERTIES SWIG_FLAG “-importall”)

to the CMakeLists file, but it doesn’t work.

Any suggestion or documentation related to this issue are more than welcome!

Andrea
--

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
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: Integration between C++ cmake and python (and google tests)

William S Fulton
On 29 June 2016 at 09:48, Andrea Bianco <[hidden email]> wrote:
> Dear All,
>
> first of all, hello to everyone. I like a lot the idea behind Swig and
> thanks to the developer of this fantastic project.
BTW, it is one developer, there are over 100 SWIG contributors/developers.

>>>> import DMMaker
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "DMMaker.py", line 28, in <module>
>     _DMMaker = swig_import_helper()
>   File "DMMaker.py", line 24, in swig_import_helper
>     _mod = imp.load_module('_DMMaker', fp, pathname, description)
> ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList
This is not a SWIG nor a CMake problem. You are probably missing a
function definition you have wrapped.

$ c++filt _ZTI6LpList
typeinfo for LpList

Google gcc "typeinfo for" for more info.

William

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
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: Integration between C++ cmake and python (and google tests)

Andrea Bianco
Dear William,

Thanks for the answer, and sorry for using “developer" as singular, it was just a typo mistake.

Bests,
Andrea


On 30 Jun 2016, at 10:25, William S Fulton <[hidden email]> wrote:

On 29 June 2016 at 09:48, Andrea Bianco <[hidden email]> wrote:
Dear All,

first of all, hello to everyone. I like a lot the idea behind Swig and
thanks to the developer of this fantastic project.
BTW, it is one developer, there are over 100 SWIG contributors/developers.

import DMMaker
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "DMMaker.py", line 28, in <module>
   _DMMaker = swig_import_helper()
 File "DMMaker.py", line 24, in swig_import_helper
   _mod = imp.load_module('_DMMaker', fp, pathname, description)
ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList
This is not a SWIG nor a CMake problem. You are probably missing a
function definition you have wrapped.

$ c++filt _ZTI6LpList
typeinfo for LpList

Google gcc "typeinfo for" for more info.

William


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
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: Integration between C++ cmake and python (and google tests)

Andrea Bianco
Dear All,

Some time has passed and I am still trying to figure out this strange behaviour. It seems that the undefined symbol is the default constructor, that is defined in the class, and anyway should be always automatically defined.

I have two classes: A and B. Class A has as a public member an object of kind B. there are four cpp files: A.h, A.cpp, B.h, B.cpp

and the A.i file is 

%module A
%{
#include “A.h"
%}
%include “A.h"
everything compiles, but when I try to import the A class (defined in A.h, that include  B.h) the error is kind of like:

ImportError: ./_A.so: undefined symbol: _ZTI6B

$ c++filt _ZTI6B

gives:

B::B()

the default constructor.

Should I also include B.h in the A.i file?

Bests,
Andrea 
On 30 Jun 2016, at 10:30, Andrea Bianco <[hidden email]> wrote:

Dear William,

Thanks for the answer, and sorry for using “developer" as singular, it was just a typo mistake.

Bests,
Andrea


On 30 Jun 2016, at 10:25, William S Fulton <[hidden email]> wrote:

On 29 June 2016 at 09:48, Andrea Bianco <[hidden email]> wrote:
Dear All,

first of all, hello to everyone. I like a lot the idea behind Swig and
thanks to the developer of this fantastic project.
BTW, it is one developer, there are over 100 SWIG contributors/developers.

import DMMaker
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "DMMaker.py", line 28, in <module>
   _DMMaker = swig_import_helper()
 File "DMMaker.py", line 24, in swig_import_helper
   _mod = imp.load_module('_DMMaker', fp, pathname, description)
ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList
This is not a SWIG nor a CMake problem. You are probably missing a
function definition you have wrapped.

$ c++filt _ZTI6LpList
typeinfo for LpList

Google gcc "typeinfo for" for more info.

William

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user


------------------------------------------------------------------------------

_______________________________________________
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: Integration between C++ cmake and python (and google tests)

Matthieu Brucher-2
Hi,

How did you link the module? Did you properly add all the required dependencies?

Cheers,

2016-08-24 16:21 GMT+01:00 Andrea Bianco <[hidden email]>:
Dear All,

Some time has passed and I am still trying to figure out this strange behaviour. It seems that the undefined symbol is the default constructor, that is defined in the class, and anyway should be always automatically defined.

I have two classes: A and B. Class A has as a public member an object of kind B. there are four cpp files: A.h, A.cpp, B.h, B.cpp

and the A.i file is 

%module A
%{
#include “A.h"
%}
%include “A.h"
everything compiles, but when I try to import the A class (defined in A.h, that include  B.h) the error is kind of like:

ImportError: ./_A.so: undefined symbol: _ZTI6B

$ c++filt _ZTI6B

gives:

B::B()

the default constructor.

Should I also include B.h in the A.i file?

Bests,
Andrea 
On 30 Jun 2016, at 10:30, Andrea Bianco <[hidden email]> wrote:

Dear William,

Thanks for the answer, and sorry for using “developer" as singular, it was just a typo mistake.

Bests,
Andrea


On 30 Jun 2016, at 10:25, William S Fulton <[hidden email]> wrote:

On 29 June 2016 at 09:48, Andrea Bianco <[hidden email]> wrote:
Dear All,

first of all, hello to everyone. I like a lot the idea behind Swig and
thanks to the developer of this fantastic project.
BTW, it is one developer, there are over 100 SWIG contributors/developers.

import DMMaker
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "DMMaker.py", line 28, in <module>
   _DMMaker = swig_import_helper()
 File "DMMaker.py", line 24, in swig_import_helper
   _mod = imp.load_module('_DMMaker', fp, pathname, description)
ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList
This is not a SWIG nor a CMake problem. You are probably missing a
function definition you have wrapped.

$ c++filt _ZTI6LpList
typeinfo for LpList

Google gcc "typeinfo for" for more info.

William

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user


------------------------------------------------------------------------------

_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user




--
Information System Engineer, Ph.D.
Blog: http://blog.audio-tk.com/
LinkedIn: http://www.linkedin.com/in/matthieubrucher

------------------------------------------------------------------------------

_______________________________________________
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: Integration between C++ cmake and python (and google tests)

Andrea Bianco
Dear Matthieu,

this is the relevant part of my CMakeList file

###
# SWIG
##

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs)

include_directories(${PYTHON_INCLUDE_PATH}
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CPP_SOURCE_FILES}
   ${COMMON_INCLUDES}
            ${EIGEN3_INCLUDE_DIR}
            ${ZLIB_INCLUDE_DIR}
)

set_source_files_properties(${SWIG_PROJECTS_DIR}/DMMaker.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(${SWIG_PROJECTS_DIR}/DMMaker.i PROPERTIES SWIG_FLAG "-includeall")

swig_add_module(DMMaker python ${SWIG_PROJECTS_DIR}/DMMaker.i
                ${CPP_SOURCE_FILES}/DMMaker.cpp
                )
swig_link_libraries(DMMaker ${PYTHON_LIBRARIES} ${TIFF_LIBRARIES} jpeg jbig xz  z ${CMAKE_THREAD_LIBS_INIT})

cheers,
Andrea
On 24 Aug 2016, at 17:39, Matthieu Brucher <[hidden email]> wrote:

Hi,

How did you link the module? Did you properly add all the required dependencies?

Cheers,

2016-08-24 16:21 GMT+01:00 Andrea Bianco <[hidden email]>:
Dear All,

Some time has passed and I am still trying to figure out this strange behaviour. It seems that the undefined symbol is the default constructor, that is defined in the class, and anyway should be always automatically defined.

I have two classes: A and B. Class A has as a public member an object of kind B. there are four cpp files: A.h, A.cpp, B.h, B.cpp

and the A.i file is 

%module A
%{
#include “A.h"
%}
%include “A.h"
everything compiles, but when I try to import the A class (defined in A.h, that include  B.h) the error is kind of like:

ImportError: ./_A.so: undefined symbol: _ZTI6B

$ c++filt _ZTI6B

gives:

B::B()

the default constructor.

Should I also include B.h in the A.i file?

Bests,
Andrea 
On 30 Jun 2016, at 10:30, Andrea Bianco <[hidden email]> wrote:

Dear William,

Thanks for the answer, and sorry for using “developer" as singular, it was just a typo mistake.

Bests,
Andrea


On 30 Jun 2016, at 10:25, William S Fulton <[hidden email]> wrote:

On 29 June 2016 at 09:48, Andrea Bianco <[hidden email]> wrote:
Dear All,

first of all, hello to everyone. I like a lot the idea behind Swig and
thanks to the developer of this fantastic project.
BTW, it is one developer, there are over 100 SWIG contributors/developers.

import DMMaker
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "DMMaker.py", line 28, in <module>
   _DMMaker = swig_import_helper()
 File "DMMaker.py", line 24, in swig_import_helper
   _mod = imp.load_module('_DMMaker', fp, pathname, description)
ImportError: ./_DMMaker.so: undefined symbol: _ZTI6LpList
This is not a SWIG nor a CMake problem. You are probably missing a
function definition you have wrapped.

$ c++filt _ZTI6LpList
typeinfo for LpList

Google gcc "typeinfo for" for more info.

William

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user


------------------------------------------------------------------------------

_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user




--
Information System Engineer, Ph.D.
Blog: http://blog.audio-tk.com/
LinkedIn: http://www.linkedin.com/in/matthieubrucher


------------------------------------------------------------------------------

_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...