Xavier(6):ubuntu18.04安装casadi 报错与解决(recompile with -fPIC)

报错:

relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VClone_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC

/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VClone_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
../../../lib/libcasadi_sundials.a(nvector_serial.c.o): In function `N_VNewEmpty_Serial':
nvector_serial.c:(.text+0x1f0c): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VCloneEmpty_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f10): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VDestroy_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f14): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VSpace_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f18): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VGetArrayPointer_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f1c): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VSetArrayPointer_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f20): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VLinearSum_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f40): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VConst_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC
nvector_serial.c:(.text+0x1f48): dangerous relocation: unsupported relocation
/usr/bin/ld: ../../../lib/libcasadi_sundials.a(nvector_serial.c.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `N_VProd_Serial' which may bind externally can not be used when making a shared object; recompile with -fPIC

解决--修改CMakeLists.txt

CMakeLists.txt418左右,添加在arm架构上可以使用fPIC的编译设置

修改前:

#######################################################################
############################# -fPIC ###################################
#######################################################################
# the following commands are needed to fix a problem with the libraries
# for linux 64 bits
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
  message(STATUS "x86_64 architecture detected - setting flag -fPIC")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fPIC")
endif()

修改后:

#######################################################################
############################# -fPIC ###################################
#######################################################################
# the following commands are needed to fix a problem with the libraries
# for linux 64 bits
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64"OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
  message(STATUS "x86_64 architecture detected - setting flag -fPIC")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fPIC")
endif()

编译通过

@meng


版权声明:本文为BIT_HXZ原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。