gcc 交叉编译环境问题

2021-10-31, updated 2021-10-31

报错信息

ld: error: cannot open crt1.o: No such file or directory
ld: error: cannot open crti.o: No such file or directory
ld: error: cannot open crtbegin.o: No such file or directory
ld: error: cannot open crtend.o: No such file or directory
ld: error: cannot open crtn.o: No such file or directory
ld: error: cannot find -lgcc
ld: error: cannot find -lgcc_s
ld: error: cannot find -lc
ld: error: cannot find -lgcc
ld: error: cannot find -lgcc_s

需要配置sysroot

gcc --sysroot=/path/to/toolchain/sysroot

/path/to/toolchain/sysroot是系统头文件和库的位置

cmake 2.8添加sysroot方法

# compiler
set(CMAKE_C_COMPILER /path/to/arm-none-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /path/to/arm-none-linux-gnueabi-g++)
# sysroot location
set(MYSYSROOT /path/to/sysroots/cortexa7-vfp-neon-telechips-linux-gnueabi)
# compiler/linker flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
# cmake built-in settings to use find_xxx() functions
set(CMAKE_FIND_ROOT_PATH "${MYSYSROOT}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

cmake 3.0之后的版本可以使用CMAKE_SYSROOT

words: 228 tags: gcc