2014-11-25 97 views
1

我试图运行这个简单的CMake命令:CMake的(2.8.12.2)在Ubuntu 14.04编译器检查失败

$ cmake -D CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_CXX_COMPILER=/usr/bin/g++ ./src/ 

我得到以下输出:

-- The C compiler identification is GNU 4.8.2

-- The CXX compiler identification is GNU 4.8.2

-- Check for working C compiler: /usr/bin/gcc

-- Check for working C compiler: /usr/bin/gcc -- broken

CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message): The C compiler "/usr/bin/gcc" is not able to compile a simple test program.

的原因错误是:

gcc: error: unrecognized command line option ‘-rpath’

因为CMake的是试图用下面的命令链接:

/usr/bin/gcc -rpath /usr/local/openblas/lib CMakeFiles/cmTryCompileExec1190183239.dir/testCCompiler.c.o -o cmTryCompileExec1190183239 -rdynamic

据我所知,gcc没有单独的'-rpath'选项。我不确定为什么CMake正在尝试这样做。

还有其他人遇到过吗?解决方案?

谢谢!

PS:一些更多的信息,或许有用: 我想学习如何使用CMake的这样的目录结构非常简单:

-cmake_test/
    -bin/
    -src/
            -executable.cpp
            -CMakeLists.txt
    -CMakeLists.txt

编辑:

完整输出

$ cmake ./src/ 
-- The C compiler identification is GNU 4.8.2 
-- The CXX compiler identification is GNU 4.8.2 
-- Check for working C compiler: /usr/bin/cc 
-- Check for working C compiler: /usr/bin/cc -- broken 
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message): 
    The C compiler "/usr/bin/cc" is not able to compile a simple test program. 

    It fails with the following output: 

    Change Dir: /home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeTmp 



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

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

    make[1]: Entering directory 
    `/home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeTmp' 

    /usr/bin/cmake -E cmake_progress_report 
    /home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeTmp/CMakeFiles 
    1 

    Building C object 
    CMakeFiles/cmTryCompileExec961681416.dir/testCCompiler.c.o 

    /usr/bin/cc -o CMakeFiles/cmTryCompileExec961681416.dir/testCCompiler.c.o 
    -c 
    /home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeTmp/testCCompiler.c 


    Linking C executable cmTryCompileExec961681416 

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

    /usr/bin/cc -rpath /usr/local/openblas/lib 
    CMakeFiles/cmTryCompileExec961681416.dir/testCCompiler.c.o -o 
    cmTryCompileExec961681416 -rdynamic 

    cc: error: unrecognized command line option ‘-rpath’ 

    make[1]: *** [cmTryCompileExec961681416] Error 1 

    make[1]: Leaving directory 
    `/home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeTmp' 

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





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



-- Configuring incomplete, errors occurred! 
See also "/home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeOutput.log". 
See also "/home/gyorgy/Workspace/CPP_Tests/src/cmake_test/CMakeFiles/CMakeError.log". 
+0

如果你输入一个简单的命令,如* $ cmake ./src/*,你会得到错误吗?你能写出完整的输出吗? – fenix688 2014-11-25 09:56:47

+0

感谢您的回复。我犯了同样的错误。我已经用$ cmake的完整输出更新了原始文章./src/ – George 2014-11-25 22:57:41

+0

在删除编译器配置后,出现相同的错误是正常的。 CMake使用缓存系统来保存以前配置的信息。请删除CMakeCache.txt文件并重新运行'cmake。/ src' – Antwane 2014-11-26 10:51:52

回答

2

我向大家道歉......从导致错误我前一阵子犯了一个错误。

总之答案是,我在我的.bashrc文件下列不正确的行:

export LDFLAGS="-rpath /usr/local/openblas/lib "$LDFLAGS

和CMake的有CMakeCommonLanguageInclude.cmake模块中的以下行:

set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}"

这显然导致CMAKE_EXE_LINKER_FLAGS设置为-rpath /usr/local/openblas/lib和 因此出现错误。改变.bashrc文件后:

export LDFLAGS="-Wl,-rpath=/usr/local/openblas/lib "$LDFLAGS

的问题就解决了。

我不知道为什么这并没有拿出GUI版本虽然:-)

我可能是通过读取OSX论坛或某事搞砸.bashrc文件。

无论如何感谢您的答案!