pass on alternative g++ version to CMake settings?

General questions regarding the usage of CodeLite
amwink
CodeLite Enthusiast
Posts: 27
Joined: Mon Jun 08, 2020 4:04 pm
Genuine User: Yes
IDE Question: c++
Contact:

pass on alternative g++ version to CMake settings?

Post by amwink »

For compiling a CMake project on a system that has /usr/bin/g++-7 as its default compiler, I am using the alternative /usr/bin/g++-9 to be able to use the std::filesystem functions (-std=g++-2a). The command g++-9 -std=gnu++-2a exits as expected -- the standard option is recognised.

In the Settings -> Build Settings I am using {C++ Compiler, /usr/bin/g++-9}, {C Compiler, /usr/bin/gcc-9}, {Linker, /usr/bin/g++-9}, {Shared Object Linker, /usr/bin/g++-9 -shared -fPIC}, {Archive, /usr/bin/gcc-ar-9 rcu}. The assembler, make and gdb commands do not have specific versions.

Then after 'Run Cmake' and 'Build', the output pane shows:

Code: Select all

...
/usr/bin/c++  [ ... many options and files ... ] -std=gnu++2a [ ... more options and files ]
c++: error: unrecognized command line option '-std=gnu++2a'; did you mean '-std=gnu++03'?
c++: error: unrecognized command line option '-std=gnu++2a'; did you mean '-std=gnu++03'?
...

The CMakeOutput.log file is full of calls to

Code: Select all

/usr/bin/cc

and in the project's CMakeCache.txt it says:

Code: Select all

...
CMakeCache.txt:CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++
CMakeCache.txt:CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7
CMakeCache.txt:CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7
CMakeCache.txt:CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc
CMakeCache.txt:CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7
CMakeCache.txt:CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7
...

This happens again if I delete all those files and re-run CMake. So it not only doesn't select the version of g++ (cc?) specified in the Build Settings, but also does explicitly select a different version than specified in the Build Settings.

Isn't that odd? And is it possible to control these CMake settings via the plugin in CodeLite?

amwink
CodeLite Enthusiast
Posts: 27
Joined: Mon Jun 08, 2020 4:04 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: pass on alternative g++ version to CMake settings?

Post by amwink »

One thing I tried, which I was sure would work, was to create a directory ~/.codelite/gcc with the links:

Code: Select all

$ ls -l1 ~/.codelite/gcc | awk '{print $9,$10,$11}' | grep u
ar -> /usr/bin/gcc-ar-9
as -> /usr/bin/as
g++ -> /usr/bin/g++-9
gcc -> /usr/bin/gcc-9
gdb -> /usr/bin/gdb
make -> /usr/bin/make

and put those in the Build Settings, but the CMake setup still uses programs from /usr/bin.

DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: pass on alternative g++ version to CMake settings?

Post by DavidGH »

Hi,

(Warning: cmake isn't one of my favourite things and, apart from building CodeLite itself, I've little experience of using it.)

According to the cmake wiki there are various ways to specify which compiler to use. I suggest you try one of them, in either your project settings or CMakeLists.txt as appropriate.

Regards,

David

amwink
CodeLite Enthusiast
Posts: 27
Joined: Mon Jun 08, 2020 4:04 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: pass on alternative g++ version to CMake settings?

Post by amwink »

That's a clear answer, thanks! The reason that I hoped the settings for CMake would come from outside of the project's settings is to not have to change project settings when moving from 1 machine to another -- In CodeLite they're not in the project settings either.

But fully agree that CMake has loads of peculiarities, it's hard to cater for. It looks like the CMake -D route is the only one worth trying.

Post Reply