Re: swig Cmake linker problem

Rokas Kupstys via Swig-user <[email protected]> Tue, 24 Nov 2020 09:25:13 +0200
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
Hello,

Linker error tells you precisely what to do:

> recompile with -fPIC

-- Rokas Kupstys

On 2020-11-23 22:38, Patrick Mulder wrote:
> Hello,
> I am trying to compile and linke a simple Python wrapper with Swig and 
> CMake.
> The example repo is this:
> https://gitlab.com/bitdiver/geometrics/-/tree/swig
> However, when I try to link the geomod module I get:
> geometrics/build> ninja all
> [0/1] Re-running CMake...
> -- Configuring done
> -- Generating done
> -- Build files have been written to: 
> /home/pmu/projects/graphics/geometrics/build
> [2/2] Linking CXX shared module src/_geomod.so
> FAILED: src/_geomod.so
> : && /usr/bin/c++ -fPIC    -shared  -o src/_geomod.so 
> src/CMakeFiles/geomod.dir/CMakeFiles/geomod.dir/geometryPYTHON_wrap.cxx.o 
> /usr/lib64/libpython3.6m.so /usr/local/lib/libPNGwriter.a 
> src/libgeometry.a /usr/local/lib/libPNGwriter.a /usr/lib64/libpng.so 
> /usr/lib64/libz.so -lm /usr/lib64/libfreetype.so && :
> /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 
> src/libgeometry.a(geometry.cc.o): relocation R_X86_64_PC32 against 
> symbol `_ZN9pngwriter4lineEiiiiiii' can not be used when making a 
> shared object; recompile with -fPIC
> /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 
> /usr/local/lib/libPNGwriter.a(pngwriter.cc.o): relocation R_X86_64_32 
> against `.rodata.str1.8' can not be used when making a shared object; 
> recompile with -fPIC
> /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: 
> final link failed: nonrepresentable section on output
> collect2: error: ld returned 1 exit status
> ninja: build stopped: subcommand failed.
> Do you see if I miss a compiler flag?
> Or is something wrong with my Swig module file:
> %module geomod
> %include "stdint.i"
> %include "std_string.i"
> // Add necessary symbols to generated header
> %{
> #include <geometry.hh>
> int draw_line(std::string fname, int x0, int y0, int x1, int y1);
> %}
>
> int draw_line(std::string fname, int x0, int y0, int x1, int y1);
> //%include "../geometry.hh"
>
>
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user

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