jaeandersson / swig

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
http://www.swig.org
Other
23 stars 19 forks source link

multiple definitions of SWIG_Matlab_ functions when using modules #91

Closed yuriy-kozlov closed 6 years ago

yuriy-kozlov commented 6 years ago

I get theses errors when linking multiple modules produced with swig -matlab:

mymodule2_wrap_matlab.o: In function SWIG_Matlab_ExitFcn': mymodule2_wrap_matlab.cxx:(.text+0x0): multiple definition ofSWIG_Matlab_ExitFcn' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x0): first defined here mymodule2_wrap_matlab.o: In function SWIG_Matlab_NewPointer(SwigPtr**, void*, swig_type_info*, int)': mymodule2_wrap_matlab.cxx:(.text+0xb30): multiple definition ofSWIG_Matlab_NewPointer(SwigPtr, void, swig_type_info, int)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0xcc0): first defined here mymodule2_wrap_matlab.o: In function SWIG_Matlab_DeletePointer(SwigPtr*)': mymodule2_wrap_matlab.cxx:(.text+0xd70): multiple definition ofSWIG_Matlab_DeletePointer(SwigPtr*)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0xf00): first defined here mymodule2_wrap_matlab.o: In function mxCreateReference': mymodule2_wrap_matlab.cxx:(.text+0xf80): multiple definition ofmxCreateReference' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x12e0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_delete_MatlabSwigIterator(int, mxArray_tag, int, mxArray_tag)': Makefile:71: recipe for target '/home/yk/src/mymainmodule/lib/linux-g++/release/matlab/mymainmoduleMEX.so' failed mymodule2_wrap_matlab.cxx:(.text+0xf90): multiple definition of `_wrap_delete_MatlabSwigIterator(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1300): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_value(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1060): multiple definition of `_wrap_MatlabSwigIterator_value(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x13e0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_incr__SWIG_0(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1160): multiple definition of `_wrap_MatlabSwigIterator_incr__SWIG_0(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x14e0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_incr__SWIG_1(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x12d0): multiple definition of `_wrap_MatlabSwigIterator_incr__SWIG_1(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1650): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_incr(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x13f0): multiple definition of `_wrap_MatlabSwigIterator_incr(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1780): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_decr__SWIG_0(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x14e0): multiple definition of `_wrap_MatlabSwigIterator_decr__SWIG_0(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1880): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_decr__SWIG_1(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1650): multiple definition of `_wrap_MatlabSwigIterator_decr__SWIG_1(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x19f0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_decr(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1770): multiple definition of `_wrap_MatlabSwigIterator_decr(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1b20): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_distance(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1860): multiple definition of `_wrap_MatlabSwigIterator_distance(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1c20): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_equal(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x19f0): multiple definition of `_wrap_MatlabSwigIterator_equal(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1db0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_copy(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1b80): multiple definition of `_wrap_MatlabSwigIterator_copy(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x1f40): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_next(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1c60): multiple definition of `_wrap_MatlabSwigIterator_next(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2020): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_previous(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1d80): multiple definition of `_wrap_MatlabSwigIterator_previous(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2140): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_advance(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x1ea0): multiple definition of `_wrap_MatlabSwigIterator_advance(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2260): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_eq(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x2020): multiple definition of `_wrap_MatlabSwigIterator_eq(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x23e0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_ne(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x2170): multiple definition of `_wrap_MatlabSwigIterator_ne(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2530): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_TODOincr(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x22c0): multiple definition of `_wrap_MatlabSwigIterator_TODOincr(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2680): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_TODOdecr(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x23b0): multiple definition of `_wrap_MatlabSwigIterator_TODOdecr(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2770): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_plus(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x24a0): multiple definition of `_wrap_MatlabSwigIterator_plus(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2860): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_minus__SWIG_0(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x2630): multiple definition of `_wrap_MatlabSwigIterator_minus__SWIG_0(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x29f0): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_minus__SWIG_1(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x27c0): multiple definition of `_wrap_MatlabSwigIterator_minus__SWIG_1(int, mxArray_tag, int, mxArray_tag)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2b80): first defined here mymodule2_wrap_matlab.o: In function `_wrap_MatlabSwigIterator_minus(int, mxArray_tag, int, mxArray_tag)': mymodule2_wrap_matlab.cxx:(.text+0x2910): multiple definition of `_wrap_MatlabSwigIterator_minus(int, mxArray_tag, int, mxArray_tag**)' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x2cd0): first defined here mymodule2_wrap_matlab.o: In function SWIG_Matlab_LoadModule()': mymodule2_wrap_matlab.cxx:(.text+0x6600): multiple definition ofSWIG_Matlab_LoadModule()' mymainmodule_wrap_matlab.o:mymainmodule_wrap_matlab.cxx:(.text+0x11fd0): first defined here

I think the problem is that these functions need to be declared with SWIGRUNTIME in the .swg files to keep them internal (static) to each module.

From http://www.swig.org/Doc3.0/Modules.html#Modules_nn2

The runtime functions are private to each SWIG-generated module. That is, the runtime functions are declared with "static" linkage and are visible only to the wrapper functions defined in that module.

yuriy-kozlov commented 6 years ago

I think I misunderstood how swig modules work and in fact my Python modules did not work even though they did not give link-time errors. I put each module in a separate SO (mexfile) and that works better. I still think these functions should be marked internal though.

jaeandersson commented 6 years ago

Yes, the modules need to be compiled as separate shared libraries.