Swig problem for python3 setup.py build

bitdiver <[email protected]> Thu, 10 Dec 2020 22:18:49 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <trinity-2ec8e5d6-04c4-49ee-8f95-663c5f168009-1607635129334@3c-app-gmx-bap47>
Hello,

I was able to build the module with CMake and could draw some simple graphics in Jupyter (thanks to Trokas to recompile both pngwriter and the extension with fpic)

However, to have other people use the module, I'd like to run the build with setup.py

Trying a build with python3 setup.py build gives

.../geometrics> python3 setup.py build

running build

running build_ext

building '_geomod' extension

swigging src/swig/geometry.i to src/swig/geometry_wrap.cpp

swig -python -c++ -py3 -o src/swig/geometry_wrap.cpp src/swig/geometry.i

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -DOPENSSL_LOAD_CONF -fwrapv -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -fPIC -Isrc -I/home/pmu/projects/graphics/geometrics/local/include -I/usr/include/python3.6m -c src/swig/geometry_wrap.cpp -o build/temp.linux-x86_64-3.6/src/swig/geometry_wrap.o -std=c++17

In file included from src/geometry.hh:8:0,

from src/swig/geometry_wrap.cpp:3133:

/usr/local/include/pngwriter.h:66:10: fatal error: ft2build.h: No such file or directory

#include <ft2build.h>

^~~~~~~~~~~~

compilation terminated.

error: command 'gcc' failed with exit status 1

It seems the pngwriter library is build as dependency.

Please see the current setup.py definition in:

https://gitlab.com/bitdiver/geometrics/-/blob/master/setup.py

What would be the best approach to do this?

Thanks for your help.

Gesendet: Dienstag, 24. November 2020 um 08:25 Uhr

Von: "Rokas Kupstys via Swig-user" <[email protected]>

An: [email protected]

Betreff: Re: [Swig-user] swig Cmake linker problem

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

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