2

I am trying to build Trilinos on my OS X 10.11.6 laptop and keep encountering the following problem: CMake uses Apple's Clang instead of GCC

... 

Probing the environment ...

-- USE_XSDK_DEFAULTS='FALSE'
-- CMAKE_BUILD_TYPE='RELEASE'
-- BUILD_SHARED_LIBS='FALSE'
-- CMAKE_C_COMPILER_ID='AppleClang'
-- CMAKE_C_COMPILER_VERSION='7.3.0.7030031'
-- CMAKE_CXX_COMPILER_ID='AppleClang'
-- CMAKE_CXX_COMPILER_VERSION='7.3.0.7030031'

...

Despite the fact that I passed gcc/g++ address as an argument in call:

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

I installed GCC and G++ separately:

$ gcc --version

gcc (GCC) 4.9.2 20141029 (prerelease)

Copyright (C) 2014 Free Software Foundation, Inc.

UPD If anybody's interested, I've given up and moved development to ubuntu. If you find a way to do this, please comment below

  • Please type `type gcc` on the shell and report back the output. Also type `/usr/bin/gcc --version` and report the output. – fuz Sep 13 '16 at 19:25
  • @FUZxxl, `/usr/bin/gcc` gives Apple's LLVM, but `/usr/local/bin/gcc` gives GNU compiler. I tried passing `/usr/local/bin/gcc` to CMake with the same lack of success – Ruslan Shaydulin Sep 15 '16 at 19:00
  • 1
    Make sure to remove the cached configuration cmake generated in the previous pass to ensure that the updated compiler is actually used. – fuz Sep 15 '16 at 22:08

1 Answers1

-1

When compiler is set explicitely, CMake doesn't try to guess its identification (variables *_COMPILER_ID and *_COMPILER_VERSION.

If you want (and usually you do want) this identification to correctly reflect your compiler, you need to set these variables explicitely too.

For setup several variables describing building environment you may use toolchain files.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • The thing is, the Apple's llvm fails to compile simple test code with fortran, while GNU gcc is supposed to do this okay. Also, the error info for build fail specifically says that it tried to use compiler with address `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`, so it certainly doesn't pick up right compiler – Ruslan Shaydulin Sep 15 '16 at 19:01
  • Hmm, actually both `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` variables are cached. You may inspect *CMakeCache.txt* file in build directory and check their values. – Tsyvarev Sep 15 '16 at 19:17
  • 1
    @RuslanShaidulin That's cause llvm doesn't support Fortran. Why do you tag this question as C when you try to compile a Fortran project? – fuz Sep 15 '16 at 22:08