简体   繁体   English

用cmake交叉编译libwebsockets

[英]Cross compiling libwebsockets with cmake

I am trying to cross-compile libwebsockets with cmake, but I am getting the below errors: 我正在尝试使用cmake交叉编译libwebsockets,但是出现以下错误:

root@ubuntu-Latitude-E5450:/home/ubuntu/Downloads/libwebsockets/build# cmake .. -DCMAKE_INSTALL_PREFIX_PATH=/home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/ -DCMAKE_LIBRARY_PATH=/home/ubuntu/toolchain/sysroots/aarch64-oe-linux/usr/lib/ -DCMAKE_SYSROOT=/ubuntu/home/das_toolchain/sysroots/aarch64-oe-linux/ -DCMAKE_TOOLCHAIN_FILE=../cross-arm-oe-linux-gnueabi.cmake -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_SSL=0 -DLWS_WITH_ZIP_FOPS=0 -DLWS_WITH_ZLIB=0
-- The C compiler identification is GNU 4.9.3
-- Check for working C compiler: /home/ubuntu/das_toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc
-- Check for working C compiler: /home/ubuntu/das_toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc -- broken
CMake Error at /usr/local/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
  The C compiler
  "/home/ubuntu/das_toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc"
  is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: /home/ubuntu/Downloads/libwebsockets/build/CMakeFiles/CMakeTmp



  Run Build Command:"/usr/bin/make" "cmTC_515b7/fast"

  /usr/bin/make -f CMakeFiles/cmTC_515b7.dir/build.make
  CMakeFiles/cmTC_515b7.dir/build

  make[1]: Entering directory
  `/home/ubuntu/Downloads/libwebsockets/build/CMakeFiles/CMakeTmp'

  Building C object CMakeFiles/cmTC_515b7.dir/testCCompiler.c.o

/home/ubuntu/das_toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc
  --sysroot=/ubuntu/home/das_toolchain/sysroots/aarch64-oe-linux/ -o
  CMakeFiles/cmTC_515b7.dir/testCCompiler.c.o -c
  /home/ubuntu/Downloads/libwebsockets/build/CMakeFiles/CMakeTmp/testCCompiler.c


  Linking C executable cmTC_515b7

  /usr/local/bin/cmake -E cmake_link_script
  CMakeFiles/cmTC_515b7.dir/link.txt --verbose=1


  /home/ubuntu/das_toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc
  --sysroot=/ubuntu/home/das_toolchain/sysroots/aarch64-oe-linux/ -rdynamic
  CMakeFiles/cmTC_515b7.dir/testCCompiler.c.o -o cmTC_515b7


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot open crt1.o: No such file or directory


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot open crti.o: No such file or directory


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot open crtbegin.o: No such file or directory


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot open crtend.o: No such file or directory


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot open crtn.o: No such file or directory


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot find -lgcc


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot find -lgcc_s


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot find -lc


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot find -lgcc


  /home/ubuntu/toolchain/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.9.3/real-ld:
  error: cannot find -lgcc_s

  collect2: error: ld returned 1 exit status

  make[1]: *** [cmTC_515b7] Error 1

  make[1]: Leaving directory
  `/home/ubuntu/Downloads/libwebsockets/build/CMakeFiles/CMakeTmp'

  make: *** [cmTC_515b7/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:146 (project)


-- Configuring incomplete, errors occurred!
See also "/home/ubuntu/Downloads/libwebsockets/build/CMakeFiles/CMakeOutput.log".
See also "/home/ubuntu/Downloads/libwebsockets/build/CMakeFiles/CMakeError.log".

I have specified the CMAKE_SYSROOT in the toolchain file and also specified the same in my command line while building. 我在工具链文件中指定了CMAKE_SYSROOT,并且在构建时在命令行中也指定了CMAKE_SYSROOT。 Where am I going wrong with this? 我在哪里错呢?

Your help would be appreciated. 您的帮助将不胜感激。

Below is my toolchain file: 以下是我的工具链文件:

#
# CMake Toolchain file for crosscompiling on ARM.
#
# This can be used when running cmake in the following way:
#  cd build/
#  cmake .. -DCMAKE_TOOLCHAIN_FILE=../cross-arm-oe-linux-gnueabi.cmake
#

set(CROSS_COMPILER_PATH /home/ubuntu/das_toolchain/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/)
set(CROSS_PATH /ubuntu/home/das_toolchain/sysroots/aarch64-oe-linux/)
set(TOOLCHAIN_PREFIX arm-oe-linux-gnueabi-)
#set(SYSROOT --sysroot=/ubuntu/home/das_toolchain/sysroots/aarch64-oe-linux/)
set(CMAKE_SYSROOT /ubuntu/home/das_toolchain/sysroots/aarch64-oe-linux/)

# Target operating system name.
#set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_NAME Arm)

# Name of C compiler.
#set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-linux-gnueabihf-gcc")
#set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-linux-gnueabihf-g++")
#set(CMAKE_C_COMPILER "${CROSS_PATH}${TOOLCHAIN_PREFIX}gcc ${SYSROOT}")
#set(CMAKE_CXX_COMPILER "${CROSS_PATH}${TOOLCHAIN_PREFIX}g++ ${SYSROOT}")
set(CMAKE_C_COMPILER "${CROSS_COMPILER_PATH}${TOOLCHAIN_PREFIX}gcc")
set(CMAKE_CXX_COMPILER "${CROSS_COMPILER_PATH}${TOOLCHAIN_PREFIX}g++")
#set(CMAKE_C_FLAGS ${SYSROOT})
#set(CMAKE_CXX_FLAGS ${SYSROOT})

# Where to look for the target environment. (More paths can be added here)
set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}")

# Adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment only.
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# Search headers and libraries in the target environment only.
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

In my experience, using CMAKE_SYSROOT can cause issues like this sometimes since it passes the --sysroot flag to the compiler, which can confuse it. 以我的经验,使用CMAKE_SYSROOT有时会引起类似的问题,因为它会将--sysroot标志传递给编译器,这可能会使它感到困惑。 To tell CMake where to find libraries, without affecting the actual compiler options, just set CMAKE_PREFIX_PATH instead of CMAKE_SYSROOT . 要告诉CMake在哪里找到库,而又不影响实际的编译器选项,只需设置CMAKE_PREFIX_PATH而不是CMAKE_SYSROOT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM