这几天编译同文trime输入法时遇到一个没法解决的问题,到网上搜也没有答案难道没人遇到类似的问题。问题描述如下:
D:projectandriodtrime-developappsrcmainjniCMakeLists.txt : C/C++ debug|x86 : CMake Error at C:/Users/Administrator/AppData/Local/Android/Sdk/cmake/3.18.1/share/cmake-3.19/Modules/CMakeTestCCompiler.cmake:68 (message): The C compiler "C:/Users/Administrator/AppData/Local/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: D:/project/andriod/trime-develop/app/.cxx/cmake/debug/x86/CMakeFiles/CMakeTmp Run Build Command(s):C:UsersAdministratorAppDataLocalAndroidSdkcmake3.18.1binninja.exe cmTC_3c0a9 && ninja: fatal: couldn't open nul
于是找到CMakeTestCCompiler.cmake文件发现是以下代码报错:
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c "#ifdef __cplusplusn" "# error "The CMAKE_C_COMPILER is set to a C++ compiler"n" "#endifn" "#if defined(__CLASSIC_C__)n" "int main(argc, argv)n" " int argc;n" " char* argv[];n" "#elsen" "int main(int argc, char* argv[])n" "#endifn" "{ (void)argv; return argc-1;}n") #message(FATAL_ERROR "hello world") try_compile(CMAKE_C_COMPILER_WORKS ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c OUTPUT_VARIABLE __CMAKE_C_COMPILER_OUTPUT) # Move result from cache to normal variable. set(CMAKE_C_COMPILER_WORKS ${CMAKE_C_COMPILER_WORKS}) unset(CMAKE_C_COMPILER_WORKS CACHE) __TestCompiler_restoreTryCompileTargetType() if(NOT CMAKE_C_COMPILER_WORKS) PrintTestCompilerResult(CHECK_FAIL "broken") file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Determining if the C compiler works failed with " "the following output:n${__CMAKE_C_COMPILER_OUTPUT}nn") string(REPLACE "n" "n " _output "${__CMAKE_C_COMPILER_OUTPUT}") message(FATAL_ERROR "hello world, The C compilern "${CMAKE_C_COMPILER}"n" "is not able to compile a simple test program.nIt fails " "with the following output:n ${_output}nn" "CMake will not be able to correctly generate this project.")
其中message命令中的hello world是我为了定位问题加的。file命令将测试代码写入testCCompiler.c,try_compile命令进行编译,成功则CMAKE_C_COMPILER_WORKS的值为true。就是这么简单的测试代码居然报错!!
于是又从github上把ninja代码下载下来,找到subprocess-win32.cc文件找到报错的地方如下:
bool Subprocess::Start(SubprocessSet *set, const string &command) { HANDLE child_pipe = SetupPipe(set->ioport_); SECURITY_ATTRIBUTES security_attributes; memset(&security_attributes, 0, sizeof(SECURITY_ATTRIBUTES)); security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); security_attributes.bInheritHandle = TRUE; // Must be inheritable so subprocesses can dup to children.必须是可继承的,以便子进程可以复制到子进程 // HANDLE nul = CreateFileA("D:testCCompiler.c", GENERIC_READ, HANDLE nul = CreateFileA("NUL", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, &security_attributes, OPEN_EXISTING, 0, NULL); if (nul == INVALID_HANDLE_VALUE) Fatal("hello world, couldn't open nul");
发现CreateFileA函数的第一个参数居然NUL,心想google这个坑货害人啊。于是改成D:testCCompiler.c结果发现也不对。这时就无计可施了 哭!!
编译ninja的时候明明好好的,用gcc编译也成功msvc编译也没问题,为什么在android studio上编译就失败呢。心想是不是ndk的cmake版本太低于是升级到3.18.1也没用。于是将本地cmake 3.9中的文件替换掉ndk中的文件重新编译结果还是一样。
推测因为用本地cmake编译ninja时用的是make没用ninja,而android studio用的是ninja所以才会出错。到此时已经无计可施了。现在只有两个办法一个是修复ninja问题,一个是用make替换ninja看看。刚接触安卓开发很多东西还不熟。
把ndk下cmake中的ninja.exe复制到独立安装的cmake的bin文件夹中,用ninja替换make果然还是不行,输出如下:
PS D:projectcodeninja-masterbuild_ninja> cmake -G Ninja .. -- The C compiler identification is GNU 8.1.0 -- The CXX compiler identification is GNU 8.1.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - failed -- Check for working C compiler: C:/mingw64/bin/gcc.exe -- Check for working C compiler: C:/mingw64/bin/gcc.exe - broken CMake Error at E:/Program Files/CMake/share/cmake-3.19/Modules/CMakeTestCCompiler.cmake:68 (message): The C compiler "C:/mingw64/bin/gcc.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: D:/projectcode/ninja-master/build_ninja/CMakeFiles/CMakeTmp Run Build Command(s):E:/PROGRA~2/CMake/bin/ninja.exe cmTC_753f8 && ninja: fatal: couldn't open nul CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:6 (project) -- Configuring incomplete, errors occurred! See also "D:/projectcode/ninja-master/build_ninja/CMakeFiles/CMakeOutput.log". See also "D:/projectcode/ninja-master/build_ninja/CMakeFiles/CMakeError.log". PS D:projectcodeninja-masterbuild_ninja>
不行就只能换平台了拿到ubuntu上再看了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)