My meson.build
constructs an erroneous c++
or ld
command: some error about -fPIC
, what's it mean and how to rectify?
#14068
-
Lemme share the error message at hand first, during a
It's just this very-tiny minimal project for now, here's the project('mo', ['cpp', 'c'])
dep_wicked = dependency('WickedEngine', static: true)
lib_gfx = library('mo_gfx', sources: ['mo_gfx/mo_gfx.cpp'], dependencies: [dep_wicked])
executable('mo.exec', sources: ['main.cpp'], link_with: [lib_gfx]) The #include "mo_gfx/mo_gfx.h"
int main(int argc, char** argv) {
moStart();
return 0;
} The #include <stdio.h>
#include <WickedEngine/WickedEngine.h>
void moStart() {
printf("HolaMain\n");
} So this happens from just the (What's this WickedEngine? Exists in my |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This file is built without support for using in a shared library. Shared libraries require PIC. Static libraries can optionally use PIC, but if they don't use PIC then you can only link them into executables, not into shared libraries. There are security considerations that suggest using PIC for all code, even code intended for static linking into a binary, and also modest performance penalties for doing so (32-bit systems). Many people simply compile all objects with PIC and save themselves a lot of trouble. There's nothing meson can do about this -- the cmake-built static library was compiled with options that don't support using it in a shared library. You need to recompile. FWIW, meson defaults to PIC on static libraries but provides a global meson-level option "b_staticpic" for people who know their static libraries will only be used by executables (never shared libraries), and would prefer the slight speed bonus and corresponding security tradeoff. |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for the informative instructive explanation! Much appreciated. Will try a Wicked build with -DCMAKE_POSITION_INDEPENDENT_CODE=ON first; if failure, will change my |
Beta Was this translation helpful? Give feedback.
This file is built without support for using in a shared library. Shared libraries require PIC. Static libraries can optionally use PIC, but if they don't use PIC then you can only link them into executables, not into shared libraries.
There are security considerations that suggest using PIC for all code, even code intended for static linking into a binary, and also modest performance penalties for doing so (32-bit systems). Many people simply compile all objects with PIC and save themselves a lot of trouble.
There's nothing meson can do about this -- the cmake-built static library was compiled with options that don't supp…