cmake无法找到libstdc ++

时间:2016-02-04 12:30:14

标签: cmake cross-compiling libstdc++ mingw-w64

(使用elementaryOS / Ubuntu)

我正在交叉编译x265,我鼓励烦人的问题。出于某种原因,cmake不想接受-static-libstdc ++,因为ld显然无法找到它。 Cmake是从源代码构建的,如果我将libstdc ++ - 6.dll从mingw-w64 libs复制到带有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在哪里寻找它。

1 个答案:

答案 0 :(得分:0)

我设法解决了这个问题。我混淆的原因是你可以使用-static-libgcc这一事实,所以我认为即使是-static-libstdc ++也应该有效。问题是确实存在库,而不是libstdc ++的.a文件。使用脚本时,可以使用此参数禁用这些参数。然后两个-static-lib选项都运行良好。

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