Open neel opened 4 years ago
I see the same thing.
It looks like forcing -fPIC
will fix this. Here's my changes to CMakeRC.cmake:
# Generate the actual static library. Each source file is just a single file
# with a character array compiled in containing the contents of the
# corresponding resource file.
add_library(${name} STATIC ${libcpp})
set_property(TARGET ${name} PROPERTY CMRC_LIBDIR "${libdir}")
set_property(TARGET ${name} PROPERTY CMRC_NAMESPACE "${ARG_NAMESPACE}")
target_link_libraries(${name} PUBLIC cmrc::base)
set_property(TARGET ${name} PROPERTY CMRC_IS_RESOURCE_LIBRARY TRUE)
set_property(TARGET ${name} PROPERTY POSITION_INDEPENDENT_CODE ON)
Note the last line.
I'm just not quite sure if that's a general solution.
If your root project is a shared library I think that you should apply the following in your CMakeLists.txt:
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
before adding dependencies, to compile them with -fPIC.
Or maybe try adding a property only to cmrc resource library after cmrc_add_resource_library call.
cmrc_add_resource_library(foo-resources ALIAS foo::rc NAMESPACE foo ...)
set_property(TARGET foo::rc PROPERTY POSITION_INDEPENDENT_CODE ON)
Let me know how these options work for you - to not need to modify the CMakeRC.cmake file
Thanks @themarpe. You would have to do
set_property(TARGET foo-resources PROPERTY POSITION_INDEPENDENT_CODE ON)
in your example (aliases are not permitted in set_property()
), but your comment was spot-on. Thanks!
@neel @themarpe I would suggest closing this issue. This ^^^ is the right answer. It might be worth putting into the docs.
Linker error when I try to link with cmrc generated library with a
SHARED
library.I want the shared library to be statically linked with the
cmrc_add_resource_library
generated targetthelibx-resources
.If I remove that
SHARED
then everything works fine.