Open bobkocisko opened 4 years ago
I compile ANTLR normally, but I link against the static library, and got a similar error:
/usr/bin/ld: antlr-runtime-4.8/runtime/libantlr4-runtime.a(ANTLRInputStream.cpp.o): relocation R_X86_64_TPOFF32 against symbol
By adding set_property(TARGET antlr4_static PROPERTY POSITION_INDEPENDENT_CODE ON)
(adding -fPIC to build the static library), I managed to link properly.
I compile ANTLR normally, but I link against the static library, and got a similar error:
/usr/bin/ld: antlr-runtime-4.8/runtime/libantlr4-runtime.a(ANTLRInputStream.cpp.o): relocation R_X86_64_TPOFF32 against symbol
By addingset_property(TARGET antlr4_static PROPERTY POSITION_INDEPENDENT_CODE ON)
(adding -fPIC to build the static library), I managed to link properly.
Hey, did you put set_property(TARGET antlr4_static PROPERTY POSITION_INDEPENDENT_CODE ON)
in ExternalAntlr4Cpp.cmake?
I do not remember and I have not kept a copy of that project, sorry.
It is probably set wherever add_library(antlr4_static ...)
is called.
But it could also be where you call target_link_libraries(... antlr4_static ...)
.
I do not remember and I have not kept a copy of that project, sorry. It is probably set wherever
add_library(antlr4_static ...)
is called. But it could also be where you calltarget_link_libraries(... antlr4_static ...)
.
Thanks, I was able to use the cmake cache variable:
Hope this can help other people!
I added the line "set_property(TARGET antlr4_static PROPERTY POSITION_INDEPENDENT_CODE ON)" @victorpaleologue mentioned in runtime/CMakeLists.txt
like
add_library(antlr4_static STATIC ${libantlrcpp_SRC})
set_property(TARGET antlr4_static PROPERTY POSITION_INDEPENDENT_CODE ON)
It works as well.
Should be part of the documentation guys!
I'm attemping to link the cpp runtime project with the lld linker. I followed compiling on linux and it works fine with the regular linker
GNU ld (GNU Binutils for Ubuntu) 2.30
but when I attempt ldLLD 8.0.0 (compatible with GNU linkers)
it fails with the followingIf I use the following cmake switch to attempt to resolve this
cmake .. -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,notext"
I get thiswhich is very strange because cmake is supposed to be turning on -fPIC automatically when building a shared library.
But I tried to force it on anyways as follows
cmake .. -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,notext"
andcmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,notext"
and in both cases the output was identical to the aboveAny thoughts?