Cmake 无法在 qt creator/collect2 上编译简单的测试程序:错误:ld
Posted
技术标签:
【中文标题】Cmake 无法在 qt creator/collect2 上编译简单的测试程序:错误:ld【英文标题】:Cmake not able to compile simple test program on qt creator / collect2: error: ld 【发布时间】:2018-07-10 15:23:01 【问题描述】:我正在尝试使用 android NDK 构建一个 Android 项目。
我已将 NDK 添加到 QT 版本中,自动检测到构建工具包,但在运行 CMake 时出现以下错误:
Starting to parse CMake project, using: "-DCMAKE_CXX_COMPILER:STRING=/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-g++", "-DCMAKE_C_COMPILER:STRING=/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc", "-DCMAKE_PREFIX_PATH:STRING=/home/self/Qt5.9.6/5.9.6/android_x86", "-DQT_QMAKE_EXECUTABLE:STRING=/home/self/Qt5.9.6/5.9.6/android_x86/bin/qmake".
The C compiler identification is GNU 4.9.0
The CXX compiler identification is GNU 4.9.0
Check for working C compiler: /home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc
Check for working C compiler: /home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /tmp/QtCreator-Tuub3S/qtc-cmake-XXSZ1kmJ/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/ninja" "cmTC_991f8"
[1/2] Building C object CMakeFiles/cmTC_991f8.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_991f8
FAILED: cmTC_991f8
: && /home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc -rdynamic CMakeFiles/cmTC_991f8.dir/testCCompiler.c.o -o cmTC_991f8 && :
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot find -lc
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
Configuring incomplete, errors occurred!
See also "/tmp/QtCreator-Tuub3S/qtc-cmake-XXSZ1kmJ/CMakeFiles/CMakeOutput.log".
See also "/tmp/QtCreator-Tuub3S/qtc-cmake-XXSZ1kmJ/CMakeFiles/CMakeError.log".
CMake Project parsing failed.
我做错了什么?
编辑所以按照建议我下载了 NDK 10e ...问题似乎保持不变:
/usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52: error: The C compiler "/home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc" is not able to compile a simple test program.
It fails with the following output: Change Dir: /tmp/QtCreator-vkcYcW/qtc-cmake-XXyT08En/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/ninja" "cmTC_3ab69"
[1/2] Building C object CMakeFiles/cmTC_3ab69.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_3ab69 FAILED: cmTC_3ab69 : && /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc -rdynamic CMakeFiles/cmTC_3ab69.dir/testCCompiler.c.o -o cmTC_3ab69 && :
/home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-androi.d/4.9/../../../../i686-linux-android/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot open crtend_android.o: No such file or directory /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot find -lc /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
【问题讨论】:
你有什么版本的NDK? @eyllanesc 昨天下载的最新版本。 R17b Qt不支持最新版本的NDK,必须使用10e版本,查看文档:doc.qt.io/qt-5/androidgs.html @eyllanesc 很有趣。但他们推荐 10e,而不是要求。这确定是原因吗? @eyllanesc 好吧。所以请发布它作为答案:) 【参考方案1】:Qt不支持最新版本的NDK,在docs推荐使用NDK 10e
【讨论】:
@Alex 为什么不通过 Qtcreator 使用 qmake 呢?,然后适应 cmake @Alex 我要指出的是,首先你要确保你有正确的包,这样我们就可以丢弃一些可能的原因。 如何使用 QMake 构建现有项目 (github.com/mapsme/omim)? mmm,所以你要编译项目,让我看看能不能编译,我告诉你我的进度。 让我们continue this discussion in chat.以上是关于Cmake 无法在 qt creator/collect2 上编译简单的测试程序:错误:ld的主要内容,如果未能解决你的问题,请参考以下文章
cmake 不使用 QT4_automoc 生成 Qt moc 文件