代码之家  ›  专栏  ›  技术社区  ›  SailorCire

cmake无法在trival文件上检测到c编译器

  •  1
  • SailorCire  · 技术社区  · 6 年前

    我有一个非常大的项目,我正试图从gnu make迁移到cmake。因此,我认为拥有各种变量的中介文件是一个很好的方法。

    因为我刚开始,这就是我在top_directory/vars/cmakelists.txt中所拥有的:

    cmake_minimum_required(VERSION 2.8)
    
    set(VARIABLE "value")
    

    这样,在另一个文件夹中,我可以将此行添加到cmakelists.txt:

    add_subdirectory(top_directory/vars)
    

    但是,当尝试在/vars/cmakelists.txt目录上运行cmake时,我收到以下错误:

    me@host:/tmp>cmake .
    -- The C compiler identification is unknown
    -- The CXX compiler identification is GNU 7.3.1
    -- Check for working C compiler: /usr/bin/g++
    -- Check for working C compiler: /usr/bin/g++ -- broken
    CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:52 (message):
      The C compiler
    
        "/usr/bin/g++"
    
      is not able to compile a simple test program.
    
      It fails with the following output:
    
        Change Dir: /tmp/CMakeFiles/CMakeTmp
    
        Run Build Command:"/usr/bin/gmake" "cmTC_607e9/fast"
        /usr/bin/gmake -f CMakeFiles/cmTC_607e9.dir/build.make CMakeFiles/cmTC_607e9.dir/build
        gmake[1]: Entering directory '/tmp/CMakeFiles/CMakeTmp'
        Building C object CMakeFiles/cmTC_607e9.dir/testCCompiler.c.o
        /usr/bin/g++    -o CMakeFiles/cmTC_607e9.dir/testCCompiler.c.o   -c /tmp/CMakeFiles/CMakeTmp/testCCompiler.c
        /tmp/CMakeFiles/CMakeTmp/testCCompiler.c:2:3: error: #error "The CMAKE_C_COMPILER is set to a C++ compiler"
         # error "The CMAKE_C_COMPILER is set to a C++ compiler"
           ^~~~~
        gmake[1]: *** [CMakeFiles/cmTC_607e9.dir/build.make:66: CMakeFiles/cmTC_607e9.dir/testCCompiler.c.o] Error 1
        gmake[1]: Leaving directory '/tmp/CMakeFiles/CMakeTmp'
        gmake: *** [Makefile:126: cmTC_607e9/fast] Error 2
    
    
    
    
      CMake will not be able to correctly generate this project.
    Call Stack (most recent call first):
      CMakeLists.txt
    
    
    -- Configuring incomplete, errors occurred!
    See also "/tmp/CMakeFiles/CMakeOutput.log".
    See also "/tmp/CMakeFiles/CMakeError.log".
    

    现在我 可以 通过添加 -DCMAKE_C_COMPILER=gcc 但是这真的影响了便携性。

    所以我的问题是:这是生成“变量”cmake文件的正确方法吗?为什么cmake会错误地检测到我的c编译器?

    有用信息:

    cmake --version
    cmake version 3.11.1
    CMake suite maintained and supported by Kitware (kitware.com/cmake).
    
    gcc --version
    gcc (SUSE Linux) 7.3.1 20180323 [gcc-7-branch revision 258812]
    Copyright (C) 2017 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    如果有任何额外的信息我可以提供,那么请让我知道。

    0 回复  |  直到 6 年前