Closed
Description
Describe the bug
There is an error when building with BUILD_SHARED_LIBS=OFF
that it is still trying to use POSITION_INDEPENDENT_CODE ON
To Reproduce
Steps to reproduce the behavior:
- I'm doing a cross-compilation to Playstation 2/ Playstation Portable (MIPS CPUs).
- Configuring with
cmake
cmake -Wno-dev -DCMAKE_TOOLCHAIN_FILE=$PSPDEV/psp/share/pspdev.cmake -DCMAKE_INSTALL_PREFIX=$PSPDEV/psp/sdk -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF -DJSONCPP_WITH_TESTS=OFF ..
- Compiling
make VERBOSE=1
- Error
[ 14%] Building CXX object src/lib_json/CMakeFiles/jsoncpp_object.dir/json_reader.cpp.obj
cd /Users/fjtrujy/Projects/jsoncpp/build/src/lib_json && /Users/fjtrujy/toolchains/psp/pspdev-new/bin/psp-g++ -I/Users/fjtrujy/Projects/jsoncpp/include -I/Users/fjtrujy/Projects/jsoncpp/src/lib_json/../../include -I/Users/fjtrujy/Projects/jsoncpp/build/include/json -I/Users/fjtrujy/toolchains/psp/pspdev-new/psp/include -I/Users/fjtrujy/toolchains/psp/pspdev-new/psp/sdk/include -DPSP -O2 -G0 -O3 -DNDEBUG -fPIC -Wall -Wconversion -Wshadow -Wextra -Wpedantic -Werror=strict-aliasing -std=c++11 -o CMakeFiles/jsoncpp_object.dir/json_reader.cpp.obj -c /Users/fjtrujy/Projects/jsoncpp/src/lib_json/json_reader.cpp
cc1plus: error: cannot generate position-independent code for ‘-mabi=eabi’
make[2]: *** [src/lib_json/CMakeFiles/jsoncpp_object.dir/json_reader.cpp.obj] Error 1
make[1]: *** [src/lib_json/CMakeFiles/jsoncpp_object.dir/all] Error 2
make: *** [all] Error 2
Expected behavior
The compilation should finish and just generate static libraries libjsoncpp.a
Desktop (please complete the following information):
- OS: Cross-compilation PS2/PSP
Additional context
I'm pretty sure that there is a wrong configuration in the CMakeLists
files, more concretely in the scr/lib_json/CMakeLists.txt
, over there you have:
.....
if(BUILD_OBJECT_LIBS)
set(OBJECT_LIB ${PROJECT_NAME}_object)
add_library(${OBJECT_LIB} OBJECT ${PUBLIC_HEADERS} ${JSONCPP_SOURCES})
set_target_properties(${OBJECT_LIB} PROPERTIES
OUTPUT_NAME jsoncpp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
POSITION_INDEPENDENT_CODE ON
)
....
As you can see, you're setting POSITION_INDEPENDENT_CODE ON
without checking if SHARED_LIBS
is enabled.
On my test changing this value to POSITION_INDEPENDENT_CODE OFF
make the compilation to success.
As proposed solution could be something as:
set_target_properties(${OBJECT_LIB} PROPERTIES
OUTPUT_NAME jsoncpp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
Thanks
Metadata
Metadata
Assignees
Labels
No labels