Ubuntu – QtCreator not recognizing linked libraries after upgrading Ubuntu to 20.04

cg++gccqtqt-creator

I've upgraded from Ubuntu 18.04 to 20.04 and besides some nasty grub issues most things worked out of the box. But my QtCreator (Qt Creator 4.11.0, Based on Qt 5.12.8 (GCC 9.3.0, 64 bit)) is facing problems recognizing included libraries. It's showing thousands of error messages in projects that have worked perfectly fine before the update. The error messages all look like linker error messages. Some examples:

 error: 'std::string' (aka 'int') is not a class, namespace, or enumeration
 error: no matching function for call to 'getline'
 error: member reference base type 'std::ifstream' (aka 'int') is not a structure or union
 error: no template named 'vector' in namespace 'std'
 error: unknown type name 'SystemCallFactory' //this class is from the same  project

And even some errors in the qt and std libraries:

/usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:1374: passing argument to parameter 's' here 
/usr/include/c++/8/ostream:41: candidate found by name lookup is 'std'
  • The problem occurs in both cmake and qmake projects
  • I do have (and need) different gcc and g++ versions installed (9 and 8) (reinstalled both after the update as the update-alternatives settings were broken and one dependency was upgraded from 6 to 8)

When I create a new project in QtCreator without changing anything from the default code, it's the same:

/home/$me/src/untitled/main.cpp:7: error: variable has incomplete type 'QApplication'`
/home/$me/src/untitled/main.cpp:8: error: unknown type name 'MainWindow'

Installed compilers:

update-alternatives –display gcc
gcc – auto mode
link best version is /usr/bin/gcc-8
link currently points to /usr/bin/gcc-8
link gcc is /usr/bin/gcc
/usr/bin/gcc-8 – priority 30
/usr/bin/gcc-9 – priority 20

update-alternatives –display g++
g++ – auto mode
link best version is /usr/bin/g++-8
link currently points to /usr/bin/g++-8
link g++ is /usr/bin/g++
/usr/bin/g++-8 – priority 30
/usr/bin/g++-9 – priority 20

I can still build all projects manually, again both cmake and qmake work here. Also, when I have a complete build in the build directory that's set in QtCreator, QtCreator will build my projects, even when I change something. It will still show the errors all over my code and in the issues section, but will build and run anyways, so the build commands should be fine. But when the build directory is empty, it will fail.
How can I approach this problem further?

Best Answer

Same issue here, same solution as @nou. QtCreator 4.11 still relies on clang-8, but on Ubuntu 20.04 apt will install clang-10. The following solved the problem for me:

Install clang 8

sudo apt install clang-8

Update the alternatives

sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 100

I had no need to re-install QtCreator.

Related Question