conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.95k stars 952 forks source link

[bug] invalid libcxx options with CMakeToolchain on QNX if CC has been overridden #15770

Open dsche opened 4 months ago

dsche commented 4 months ago

Environment details

Steps to reproduce

In our project we need to explicitly override the QNX compiler frontend qcc with the GCC compiler ntoaarch64-gcc in the background by supplying myproject:CXX in the profile.

Host profile:

[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9

Target profile:

[settings]
os=Neutrino
arch=armv8
compiler=qcc
compiler.libcxx=cxx
compiler.version=8.3

[env]
my-package:CC=ntoaarch64-gcc
my-package:CXX=ntoaarch64-g++
my-package:CXXFLAGS=-D_QNX_SOURCE
my-package:CFLAGS=-D_QNX_SOURCE

However, Conan just applies the libcxx setting (see libcxx_flags in conan/tools/_compilers.py) from the QCC frontend, ignoring the override, and adds a compiler option -Y _cxx, which is not recognized by the compiler (ntoaarch64-g++ ...), leading to build errors.

It would be great if there were a possibility either to explicitly disable this feature completely or to detect that the used compiler, while technically still qcc, needs a different flag.

Logs

In conan_toolchain.cmake:

string(APPEND CONAN_CXX_FLAGS " -Y _cxx")

Compiler error:

ntoaarch64-g++: error: _cxx: No such file or directory
ntoaarch64-g++: error: Unrecognized command line option '-Y'
jcar87 commented 4 months ago

Hi @dsche - thank you for reporting this.

Please bear in mind that Conan 1.x is no longer actively maintained, although we would only look at critical bug fixes. It would be good to see if this also happens using the CMakeDeps generator, rather than the legacy unsupported ones.

On the other hand, Conan works under the assumption that the qcc frontend is invoked, as recommended by the QNX SDK documentation: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/g/gcc.html - that does not recommend invoking the gcc executables directly. My recommendation would be to follow the recommended approach in the documentation, and invoke qcc with the relevant -V to specify your desired target.

if you really need to completely bypass the qcc frontend, assuming you take care of all the things that the frontend would otherwise take care of for you, you could perhaps try changing compiler=qcc to compiler=gcc in the profile, as that more accurately reflects that's happening (the os is still Neutrino).

dsche commented 4 months ago

Hi @jcar87 , thanks for the quick reply! Some comments on that:

jcar87 commented 4 months ago

I'm not sure I would consider this a bug, since we are abiding to the QNX documentation recommendations, and by expressing qcc as the compiler, then I think it makes sense for Conan to assume that it is actually the qcc frontend rather than gcc.

Is there any specific reason why gcc -V[targetname] is not a valid solution, rather than resorting to invoking the gcc frontend directly? There may be a case to raise an issue with QNX support.

Yiling1Forever9 commented 3 months ago

Environment details

  • Operating System+version: Host Ubuntu 20.04, Target QNX 7.1
  • Compiler+version: qcc (GCC 8.3 frontend)
  • Conan version: 1.54
  • Python version: 3.8

Steps to reproduce

In our project we need to explicitly override the QNX compiler frontend qcc with the GCC compiler ntoaarch64-gcc in the background by supplying myproject:CXX in the profile.

Host profile:

[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9

Target profile:

[settings]
os=Neutrino
arch=armv8
compiler=qcc
compiler.libcxx=cxx
compiler.version=8.3

[env]
my-package:CC=ntoaarch64-gcc
my-package:CXX=ntoaarch64-g++
my-package:CXXFLAGS=-D_QNX_SOURCE
my-package:CFLAGS=-D_QNX_SOURCE

However, Conan just applies the libcxx setting (see libcxx_flags in conan/tools/_compilers.py) from the QCC frontend, ignoring the override, and adds a compiler option -Y _cxx, which is not recognized by the compiler (ntoaarch64-g++ ...), leading to build errors.

It would be great if there were a possibility either to explicitly disable this feature completely or to detect that the used compiler, while technically still qcc, needs a different flag.

Logs

In conan_toolchain.cmake:

string(APPEND CONAN_CXX_FLAGS " -Y _cxx")

Compiler error:

ntoaarch64-g++: error: _cxx: No such file or directory
ntoaarch64-g++: error: Unrecognized command line option '-Y'

you can replace ntoaarch64-g++ to ${QNX_HOST}/usr/bin/q++ , it should fix your issues.