I’m trying to statically link an external library (GraphicsMagick++) into my C++ application (running on Rapsberry Pi with Raspberry Pi OS).
The project compiles, and the library works on my development Pi, but when I try to run it on another (clean installed) Pi it complains that it cannot find the library.
It seems to me that PIO is linking the library dynamically instead of static. When I run “ldd” on my executable it also shows the GraphicsMagic dependency:
At the core, that’s a GCC/Linker question. I think this answer would work there:
You should be able to give the required flags as an array ito LINKFLAGS like in the original example above. If LINKFLAGS doesn’t work with the needed order of the flags, you might be able to fall back to this method.
Actually, when I read that Stackoverflow anaswer again, it says that simply giving the full path to the .a file should link it statically. Meaning if you do a script like
might work too. (File is class auto-defined in the SCons build system. The full path may be given instead of the relative path. Make sure to check the project tasks → Advanced → Verbose Build to see the full compiler invocations.)
Using the full path to the library works. Note: The full path! I tried with relative paths but then the linker returns an error.
Besides the GraphicsMagic++ lib, I also added the main Magick library, but then I get a bunch of “undefined references”, eventough the search path is correctly set.
/usr/bin/ld: /home/pi/libs/GraphicsMagick-1.3.40/magick/.libs/libGraphicsMagick.a(libGraphicsMagick_la-operator.o): in function `QuantumPowCB':
/home/pi/libs/GraphicsMagick-1.3.40/magick/operator.c:1575: undefined reference to `GOMP_critical_name_start'
/usr/bin/ld: /home/pi/libs/GraphicsMagick-1.3.40/magick/operator.c:1575: undefined reference to `GOMP_critical_name_end'
...
I guess I might have messed something up in my experimenting and building, rebuilding, installing & removing the libraries multiple times.
I’ll try again from a clean install and give an update then.