1
votes

I'm trying to run this simple CMake command:

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

I get the following output:

-- 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.

The reason for the error is the following:

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

because CMake is trying to link with the following command:

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

to my knowledge there is no stand alone '-rpath' option with gcc. I'm not sure why CMake is trying to do this.

Did anyone else come across this? Solutions?

Thanks!

PS: Some more info that maybe useful: I'm trying to learn how to use CMake so the directory structure is very simple:

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

Edit:

Complete output for

    $ 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".
1
If you enter a simple command like $ cmake ./src/, do you get errors? could you write the complete output?fenix688
Thanks for your response. I get the same error. I've updated my original post with the complete output for $ cmake ./src/gomfy
It is normal you have the same error after removing compiler configuration. CMake work with a cache system to save information from previous configurations. Please delete CMakeCache.txt file and re-run cmake ./srcAntwane
Did you try with a newer version of CMake?fenix688
Thanks for the responses. I've deleted the Cache files and also the CMakeFiles folder. I still get the same error. I haven't tried a newer version but, I've added the CMake GUI from Synaptic and that solved the problem. With the GUI version: Simply pressing Configure and then Generate buttons generate the appropriate Makefile. What's bothering me is that -rpath command is incorrect it should be -Wl,-rpath. It's probably a bug in the test CMakeLists file, or?gomfy

1 Answers

2
votes

I apologize to everyone... The error resulted from me making a mistake a while ago.

The answer in short is that I had the following incorrect line in my .bashrc file:

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

and CMake has the following line in the CMakeCommonLanguageInclude.cmake module:

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

Which obviously resulted in setting the CMAKE_EXE_LINKER_FLAGS to -rpath /usr/local/openblas/lib and hence the error. After changing the .bashrc file to:

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

the issue was resolved.

I have no idea why this didn't come up with the GUI version though :-)

I probably messed up the .bashrc file by reading an OSX forum or something.

Anyway thanks for the answers!