Fmt: static library cannot be linked against a pie executable

Created on 8 Mar 2016  路  2Comments  路  Source: fmtlib/fmt

how to reproduce:

#include <format/format.h>
int main() {
    fmt::print("hello world");
}
$ g++ -I ./support/deps/include/ -pie test.cpp ./support/deps/lib/libcppformat.a
/usr/bin/ld: /tmp/ccPx6StM.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccPx6StM.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

Following the compiler's advice results in a working library but I don't know how to patch the cmake recipe

Most helpful comment

To enable compilation with -fPIC use the following CMake command:

cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ...

All 2 comments

To enable compilation with -fPIC use the following CMake command:

cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ...

Thanks for the correction!

Was this page helpful?
0 / 5 - 0 ratings