cmake 无法找到 libstdc++

cmake unable to find libstdc++

(使用 elementaryOS/Ubuntu)

我正在交叉编译 x265,我鼓励烦人的问题。出于某种原因,cmake 不想接受 -static-libstdc++,因为 ld 显然无法找到它。 Cmake 是从源代码构建的,在没有 -static-libstdc++ 的情况下工作得很好,如果我然后将 libstdc++-6.dll 从 mingw-w64 库复制到带有 x265.exe 的文件夹,它运行良好,但我希望它用它建造。 mingw 是用 this script 构建的,包含这些库,但我不知道 ld 在哪里寻找它们。

这是 cmake 尝试的输出:

-- cmake version 3.5.0-rc1
-- The C compiler identification is GNU 5.2.0
-- The CXX compiler identification is GNU 5.2.0
-- Check for working C compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++ -- broken
CMake Error at /usr/local/share/cmake-3.5/Modules/CMakeTestCXXCompiler.cmake:54 (message):
  The C++ compiler
  "/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++" is not
  able to compile a simple test program.

  It fails with the following output:

   Change Dir: /home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp



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

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

  make[1]: Entering directory
  `/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp'

  Building CXX object CMakeFiles/cmTC_e7611.dir/testCXXCompiler.cxx.obj

  /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++
  -static-libgcc -static-libstdc++ -o
  CMakeFiles/cmTC_e7611.dir/testCXXCompiler.cxx.obj -c
  /home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

  Linking CXX executable cmTC_e7611.exe

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

  /usr/local/bin/cmake -E remove -f CMakeFiles/cmTC_e7611.dir/objects.a

  /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-ar cr
  CMakeFiles/cmTC_e7611.dir/objects.a @CMakeFiles/cmTC_e7611.dir/objects1.rsp

  /home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++
  -static-libgcc -static-libstdc++ -Wl,--whole-archive
  CMakeFiles/cmTC_e7611.dir/objects.a -Wl,--no-whole-archive -o
  cmTC_e7611.exe -Wl,--out-implib,libcmTC_e7611.dll.a
  -Wl,--major-image-version,0,--minor-image-version,0
  @CMakeFiles/cmTC_e7611.dir/linklibs.rsp


  /home/myname/mingw-w64/mingw-w64-x86_64/lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/bin/ld:
  cannot find -lstdc++

  collect2: error: ld returned 1 exit status

  make[1]: *** [cmTC_e7611.exe] Error 1

  make[1]: Leaving directory
  `/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeTmp'

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





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


-- Configuring incomplete, errors occurred!
See also "/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeOutput.log".
See also "/home/myname/x265/build/linux/12bit/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found.  Stop.

Cmake 和下面的代码一样 运行。

cmake -DCMAKE_C_COMPILER='/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-gcc' -DCMAKE_CXX_COMPILER='/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-g++' -DCMAKE_RC_COMPILER='/home/myname/mingw-w64/mingw-w64-x86_64/bin/x86_64-w64-mingw32-windres' -DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++" -DCMAKE_C_FLAGS="-static-libgcc -static-libstdc++" -DCMAKE_TOOLCHAIN_FILE='/home/myname/x265/build/linux/build.cmake' ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DMAIN12=ON
make ${MAKEFLAGS}

build.cmake 文件在这里不是很重要,但它包含:

SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_ASM_YASM_COMPILER yasm)

关于如何使 -static-libstdc++ 工作的任何想法?我尝试在许多文件夹中链接它,但我找不到 ld 在哪里寻找它。

我设法解决了这个问题。我感到困惑的原因是您可以使用 -static-libgcc,所以我认为即使是 -static-libstdc++ 也应该可以工作。问题是确实有库,但没有 libstdc++ 的 .a 文件。使用脚本时,可以使用此参数禁用这些。那么两个 -static-lib 选项都可以正常工作。

bash ./mingw-w64-build-3.6.7 --disable-shared