Conan: Issue with CMake on Linux with 2 C++ compilers installed

Created on 15 Mar 2016  路  8Comments  路  Source: conan-io/conan

Hello,

I'm struggling to install Boost 1.60 on my Linux machine. I tried to use the package from the Conan repo but for some reason I get unresolved link errors (libstd++ symbols) from boost.

So I tried to build it from source:
conan install . -build

but it fails quickly on bzip2:

bzip2/1.0.6@lasote/stable: Installing package ca89189bc59ff53842d6beea76549f289b7b88bd
bzip2/1.0.6@lasote/stable: WARN: Forced build from source
bzip2/1.0.6@lasote/stable: Building your package in /home/aurelien/.conan/data/bzip2/1.0.6/lasote/stable/build/ca89189bc59ff53842d6beea76549f289b7b88bd
bzip2/1.0.6@lasote/stable: Copying sources to build folder
bzip2/1.0.6@lasote/stable: Generated cmake created conanbuildinfo.cmake
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is Clang 3.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /home/aurelien/.conan/data/bzip2/1.0.6/lasote/stable/build/ca89189bc59ff53842d6beea76549f289b7b88bd/conanbuildinfo.cmake:141 (message):
  Incorrect 'gcc', is not the one detected by CMake: 'Clang'
Call Stack (most recent call first):
  /home/aurelien/.conan/data/bzip2/1.0.6/lasote/stable/build/ca89189bc59ff53842d6beea76549f289b7b88bd/conanbuildinfo.cmake:12 (conan_check_compiler)
  CMakeLists.txt:4 (CONAN_BASIC_SETUP)

I think the problem is CMake auto-detects Clang as default C++ compiler, while Conan tries to use g++. And I don't know how to make Conan force the compiler being used by Cmake.

Shouln't Conan always tell cmake (via the command line?) to use the compiler I choose?

Aurelien

Most helpful comment

ask Conan to invoke cmake with the _-DCMAKE_CXX_COMPILER=g++_ argument

Personally, I would think that this would be the default behavior, since we're not typing it by hand.

All 8 comments

Hi @aurelienrb !

About the link errors in Boost 1.60, it depends on your current OS and default libstdc++. If it is libstdc++11 (modern distro), it should work, but it fails otherwise. This has been fixed and will be released in 0.8 very soon. You can try using --build flag to build boost locally in the meantime.

About the compiler, conan does not try to use g++, conan actually uses the settings specified. This is very important, to decouple dependencies management and installation from actual build and different build systems.

Probably, your problem is the auto-detection and initialization that conan does as a helper, but that is not necessary at all:

Installation step

When first run, conan auto detects your environment configuration and define some default settings in ~/.conan/conan.conf. You can easily check this step by removing such file and running conan:

$ rm ~/.conan/conan.conf
$ conan

It could happen that conan detects gcc or clang as default, depending on your system, compilers and also current values of environment variables CC, CXX.

You can always change the values in your ~/.conan/conan.conf.

When you issue a command like

$ conan install . --build

It is actually using your default values from ~/.conan/conan.conf. You can explicitly define yours:

$ conan install . -s compiler=gcc -s compiler.version=4.9 --build

This values will be stored in your project conaninfo.txt so subsequent conan commands will use them.

Build step

It is very important to note that this step is decoupled from the above, even if there is a conan build helper command, it is not necessary, as users can run their own build systems. So it is the responsibility of the user to be coherent with the settings previously defined to install dependencies, as there is no general way to do it.

In the case of cmake, conan introduces some checks, trying to help to spot possible mismatchs. But, based on users feedback, it seems that having conan selecting or modifying your compiler in your build system is something really not desired.

Please try checking this information, and if not able to solve it, please copy here your ~/.conan/conan.conf file contents, the output of gcc --version, your OS, distro, etc., so we could have a look at it. Thanks for your feedback!

@memsharded regarding the libstdc++ issue, I spent quite a lot of time trying to understand what's wrong. My install is very recent (latest Linux Mint), I have gcc 5.3 and my libstd++ seem to export the version number required by the boost libs. But so far I failed to understand what's wrong. So after a while, as you suggested, I tried to build it with Conan.

So here comes my build problem:

  • Conan correctly uses gcc as it was asked for, and I want to keep that
  • But when Conan launches cmake (from the the conanfile.py that was downloaded for bzip2) it just calls cmake without any specific option. And, for some reason, cmake decides to use clang as C++ compiler.

I'm quite new to cmake, and I tried to find how we are supposed to make it use a specific compiler. And it seems that the correct way of doing it is to invoke cmake with the CMAKE_CXX_COMPILER option or to create an env. variable named CXX (I prefer to use a command line switch).

So my problem is simple : how to ask Conan to invoke cmake with the _-DCMAKE_CXX_COMPILER=g++_ argument (or any other)? Is there such a mechanism? It not, what do you think about having such a thing?

Thanks for you help :)

ask Conan to invoke cmake with the _-DCMAKE_CXX_COMPILER=g++_ argument

Personally, I would think that this would be the default behavior, since we're not typing it by hand.

Same issue here.

I specify explicit clang (https://travis-ci.org/Croydon/code/jobs/203601861#L265) but get the error that CMake detected gcc (https://travis-ci.org/Croydon/code/jobs/203601861#L495)

The issue is that CMake is getting the compiler from the environment, so one thing would be conan settings, and the other one, the compiler that CMake decides to use. If you want to use clang, the recommended method would be the standard one, setting the CC and CXX environment variables. For convenience they can be set:

  • In the command line: $ conan install -e CC=/usr/bin/clang -e CXX (http://docs.conan.io/en/latest/reference/commands.html#conan-install)
  • In profiles (so you store all information regarding setting and environment in one place): http://docs.conan.io/en/latest/reference/config_files.html#profiles. You can also put profiles inside your repo for convenience, and address them with a relative path to the conanfile.py

Just one important note: it is very likely that many of the OSS packages you are depending on, do not provide precompiled binaries for clang. So you will have to build them from sources, collaborate with the package creators so they provide binaries for clang, or fork the recipes and create your own binaries for clang. Probably the second option is the best if clang support is very important, or the third one if it is something experimental.

Sorry, my mistake.
The variables were set so I was assuming a bug, but they were in the wrong scope...

No worries! So it worked?
Also @aurelienrb , I think this issue is now properly addressed with both environment variables (they can even be set by package -e Pkg:env=value), and profiles, so I guess this issue could be closed, not an issue any more. Please reopen if need further help or have further suggestions for improvement

Yes, it did, thanks :)

Was this page helpful?
0 / 5 - 0 ratings