Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-default compilers #13

Closed
bforsbe opened this issue Jun 22, 2016 · 5 comments
Closed

Using non-default compilers #13

bforsbe opened this issue Jun 22, 2016 · 5 comments

Comments

@bforsbe
Copy link
Contributor

bforsbe commented Jun 22, 2016

Originally reported by: Jon Diprose (Bitbucket: well-jon, GitHub: Unknown)


cmake appears to determinedly ignore both PATH and CC environment variables when deciding what compiler to use. It might be useful to others if you could add a section to your installation documentation that suggests using something like:

cmake -DCMAKE_C_COMPILER=which gcc -DCMAKE_CXX_COMPILER=which g++ ...

to get the behaviour that I was naively expecting.


@bforsbe
Copy link
Contributor Author

bforsbe commented Jun 22, 2016

Original comment by Jon Diprose (Bitbucket: well-jon, GitHub: Unknown):


OK, how do you make this not eat backticks? `? No. `? Oh, it's markdown, so with a backslash. The above should show:

cmake -DCMAKE_C_COMPILER=`which gcc` -DCMAKE_CXX_COMPILER=`which g++` ...

So I actually do:

/apps/well/cmake/2.8.12.2/bin/cmake -DCMAKE_C_COMPILER=`which gcc` -DCMAKE_CXX_COMPILER=`which g++` -DFORCE_OWN_FFTW=ON -DFORCE_OWN_FLTK=ON ../

@bforsbe
Copy link
Contributor Author

bforsbe commented Jun 22, 2016

Original comment by Bjoern Forsberg (Bitbucket: bforsbe, GitHub: bforsbe):


That's strange. I just tried on my system and it appears to work for me;

#!bash

$ gcc --version
gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
Copyright (C) 2015 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.
$ cmake ..
-- The C compiler identification is GNU 5.2.1
-- The CXX compiler identification is GNU 5.2.1
{...}
$ export CC=gcc-4.8 CXX=g++-4.8 OMPI_CC=gcc-4.8 OMPI_CXX=g++-4.8
$ cmake ..
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/gcc-4.8
-- Check for working C compiler: /usr/bin/gcc-4.8 -- works

What system are you on?

@bforsbe
Copy link
Contributor Author

bforsbe commented Jun 22, 2016

Original comment by Stefan Fleischmann (Bitbucket: sfle, GitHub: Unknown):


Hi Jon,

regarding "eating backticks", just put command lines and program output in between code tags:

$ cmake -DCMAKE_C_COMPILER=`which gcc` -DCMAKE_CXX_COMPILER=`which g++`

What is the output of "which gcc" on your system? I'm guessing it is /usr/bin/gcc which is in turn a link to something like gcc-5 or gcc-4.8.
In that case specifying the real name of the binary works just fine:

$ CC=gcc-4.8 CXX=g++-4.8 cmake .. -DGUI=OFF
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/gcc-4.8
-- Check for working C compiler: /usr/bin/gcc-4.8 -- works
...

vs.

$ CC=gcc-5 CXX=g++-5 cmake .. -DGUI=OFF
-- The C compiler identification is GNU 5.3.1
-- The CXX compiler identification is GNU 5.3.1
-- Check for working C compiler: /usr/bin/gcc-5
-- Check for working C compiler: /usr/bin/gcc-5 -- works
...

@bforsbe
Copy link
Contributor Author

bforsbe commented Jun 22, 2016

Original comment by Jon Diprose (Bitbucket: well-jon, GitHub: Unknown):


Understood - it was more that I always forget cmake doesn't do what I expect and adding it to the docs might save others a few minutes googling. As building c++11 code (or, in this case, getting avx instructions out of fftw) requires a non-standard compiler on EL6-based distros, I'm regularly using a non-standard compiler.

For this build I'm using a local build of gcc4.9.3 installed to a non-standard (but visible cluster-wide) location. We use the environment-modules package to set up the correct environment for that build. I also use the scl-provided devtoolset-1.1 (gcc4.7.2, /opt/centos/devtoolset-1.1/root/usr/bin/gcc) and devtoolset-2 (gcc4.8.2, /opt/rh/devtoolset-2/root/usr/bin/gcc) versions. It's just easier for me to set my environment up right outside the build script and use `which gcc` inside the script.

@bforsbe
Copy link
Contributor Author

bforsbe commented Jun 23, 2016

Original comment by Jon Diprose (Bitbucket: well-jon, GitHub: Unknown):


Ah. From cmake's wiki: "Any other way (like writing make CC=gcc-3.3 CXX=g++-3.3) will not work". Every day is an education...

@bforsbe bforsbe closed this as completed Jan 26, 2017
biochem-fan pushed a commit that referenced this issue Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant