Conan: Error: wrong compiler version (specified through profile)

Created on 31 Mar 2017  路  6Comments  路  Source: conan-io/conan

Hi guys,

This is just a quick question to see if there's an easy to spot error on how I'm trying to build a package. If not, I'll post a repo to reproduce the problem.

I was trying to compile with a different version of gcc than the default system-wide one. I mean, compile with gcc-5 instead of gcc-4.8:

/usr/bin/gcc -> gcc-4.8
/usr/bin/gcc-4.8
/usr/bin/gcc-5

I just read that I can do this with the profiles, with this one:

me@computer:~/.conan/profiles$ cat gcc5 
[settings]
compiler=gcc
compiler.version=5.4
compiler.libcxx=libstdc++11

[env]
CC=/usr/bin/gcc-5
CXX=/usr/bin/g++-5

the install command (conan install -pr gcc5) seems to fill conaninfo.txt properly, but cmake (cmake -G"Unix Makefiles") fails, it seems to me that the environment variables are not reaching cmake:

CMake Error at conanbuildinfo.cmake:184 (message):
  Incorrect 'gcc' version 'compiler.version=5.4' is not the one detected by
  CMake: 'GNU=4.8'
Call Stack (most recent call first):
  conanbuildinfo.cmake:227 (conan_error_compiler_version)
  conanbuildinfo.cmake:272 (check_compiler_version)
  conanbuildinfo.cmake:43 (conan_check_compiler)
  CMakeLists.txt:5 (conan_basic_setup)


-- Configuring incomplete, errors occurred!

Is there some obvious mistake here? if not, I'll post the code in a repo with all the other details. I mean, I know this is a pretty basic usage of profiles, but I can't see any difference between this and how the docs do it (mastering and reference).

The reason why I don't want to change the system-wide default is that for some time I've been using update-alternatives and changing the conan settings (-s compiler...), but it became a bad idea when I wanted to use different versions in several projects...

question

Most helpful comment

Yes, I'd say there is a misconception of the scope of the environment variables:

  • The env vars defined in the profile, they affect to the dependencies being installed. If they have to be built from sources, they will use gcc-5. But they are not permanent, they only affect while the command conan install is running.
  • when you finish conan install, you have generated a conanbuildinfo.cmake and your own project and CMakeLists.txt. Conan, or the generated conanbuildinfo.cmake will not change or define compiler. It never does it, the only thing it does is to check for consistency between the dependencies (installed with 5.4) and your current setup, which is using the system-default.
  • So your normal invocation to cmake, in your project, and your local environment must be configured to use gcc-5, probably you want something like cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/user/bin/g++-5...

Please tell me if this helps.

All 6 comments

Yes, I'd say there is a misconception of the scope of the environment variables:

  • The env vars defined in the profile, they affect to the dependencies being installed. If they have to be built from sources, they will use gcc-5. But they are not permanent, they only affect while the command conan install is running.
  • when you finish conan install, you have generated a conanbuildinfo.cmake and your own project and CMakeLists.txt. Conan, or the generated conanbuildinfo.cmake will not change or define compiler. It never does it, the only thing it does is to check for consistency between the dependencies (installed with 5.4) and your current setup, which is using the system-default.
  • So your normal invocation to cmake, in your project, and your local environment must be configured to use gcc-5, probably you want something like cmake -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=/user/bin/g++-5...

Please tell me if this helps.

Oh, ok. Yes, it was just a misconception. I guess I got confused on that because the profiles are used also with the test_package command on the cross-compile and other pages (by the way, I think there's a typo in that page, should CONAN_MAKE_GENERATOR be CONAN_CMAKE_GENERATOR?).

Yes, that helped a lot, thanks. This command worked (after the same conan install -pr gcc5):

cmake -G "Unix Makefiles" -D CMAKE_C_COMPILER=/usr/bin/gcc-5 -D CMAKE_CXX_COMPILER=/usr/bin/g++-5 .

I think I will try premake to get rid of cmake. Everytime I have to do a new thing, it's a nightmare, surfing through ambiguous documentation and stackoverflow.

Yes, I think it is a typo, thanks for telling!

The trick with conan test_package is that it is using a consumer conanfile.py with a build() method, and it will take care of applying the settings and env vars from the profile. If you want, you can use that approach too, like: http://conanio.readthedocs.io/en/latest/mastering/conanfile_py.html#use-conanfile-py-for-consumers If you are calling `cmake directly, then you have to take care yourself to provide the correct environment.

About CMake, yes, it can be a pain, but the truth is that it is very mainstream and there are lots of responses to problems in SO. Premake is good, but its usage is much lower, so less community and when there are problems (even if they are less problems, there will be), it might be also difficult to find solutions.

Ah, before creating this issue I actually tried the other approach you mention but couldn't make it work, because I was doing the build in a subfolder.

Now I tried harder and it worked with the next build() method in the conanfile.py (conan new generates the method in the other style with raw cmake commands):

    def build(self):
        cmake = CMake(self.settings)
        cmake.configure(self, source_dir=self.conanfile_directory, build_dir="./")
        cmake.build(self)

and the commands:

mkdir build && cd build
conan install -pr gcc5 ..
conan build ..

Just leaving this here for future reference on how to do that :D

Thanks for the tip!. I have added a new issue for 0.23 (0.22 is already packed), to revise the develop flows, and probably this deserves being changed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omicronns picture omicronns  路  3Comments

Polibif picture Polibif  路  3Comments

petermbauer picture petermbauer  路  3Comments

mpdelbuono picture mpdelbuono  路  3Comments

zlalanne picture zlalanne  路  3Comments