Qt how to change to C++17 - c++

I couldn't perform #include <variant> in Qt 5.14. I've tried to change the .pro file by adding CONFIG += c++17 or CONFIG += c++1z warn_on or QMAKE_CXXFLAGS += -std=c++17 but none of them work.
Any fix to this?

The reason that my Qt doesnt recognize variant module is because it is run by gcc-5. So I updated gcc and g++ to version 7:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y
This is to update the symbolic links to version 7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 \
--slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --config gcc
gcc --version
g++ --version

Related

CMAKE_CXX_COMPILER_VERSION is pointing to the old GCC version

I have upgraded my GCC using:
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install gcc-8 g++-8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 70 --slave /usr/bin/g++ g++ /usr/bin/g++-8
Running any of these commands:
$ gcc --version
$ g++ --version
$ c++ --version
$ /usr/bin/gcc --version
$ /usr/bin/g++ --version
$ /usr/bin/c++ --version
would show (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0 confirming that version 8.1 has been installed.
When running ./configure on cmake-3.12.1 I downloaded from its website I get:
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
However when trying to make my actual project:
CMake Error at CMakeLists.txt:24 (message):
GCC version must be at least 7.1! 5.4.0
This is my CMakeLists.txt:
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# require at least gcc 7.1
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1)
message(FATAL_ERROR "GCC version must be at least 7.1! " ${CMAKE_CXX_COMPILER_VERSION})
endif()
endif()
As Shawn, Tsyvarev and hellow have mentioned in the comments, this problem is caused by CMake cache file which was located inside /build/. Deleting the file solved the issue.

header file <execution> missing in gcc 7.2 (Ubuntu) : how to solve it?

few days ago I updated in my Ubuntu 16.04 Server Edition gcc to gcc 7.2 version:
gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~16.04)
which should be the most updated version of gcc available for Ubuntu
Now, compiling an example of a book,
g++ -std=c++17 auto_parallel.cpp -oauto_parallel
auto_parallel.cpp:5:10: fatal error: execution: No such file or directory
include <execution>
~~~~~~~~~~
compilation terminated.
How to solve the problem?
Thanks in advance. Marco
update your GUN compiler to version9, according to(https://en.cppreference.com/w/cpp/compiler_support
and https://www.bojankomazec.com/2020/03/upgrading-gnu-cc-compilers-on-ubuntu.html)
sudo apt install -y gcc-9 g++-9 -y
and remap your compiler to gcc-9
sudo rm /usr/bin/g++
sudo ln -s /usr/bin/g++-9 /usr/bin/g++
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-9 /usr/bin/gcc
Verify the compiler version
ls -la /usr/bin/gcc
ls -la /usr/bin/g++

travis ci make -std=c++14 not recognized

I have the error g++: error: unrecognized command line option ‘-std=c++14’ when building my project with travis ci using premake (https://travis-ci.org/S6066/Teal/builds/171980872)
My premake script: https://github.com/S6066/Teal/blob/master/build/premake5.lua
My travis ci file: https://github.com/S6066/Teal/blob/master/.travis.yml
Thanks for help.
Edit: g++ --version gives me 4.8.5, so the real problem is Travis won't compile with g++ 6
I did these scripts for a github project and c++14 works:
This is an example of a .travis.yml:
sudo: required
dist: trusty
language: cpp
compiler: g++
install: export CXX="g++-5"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
notifications:
email:
on_success: never
on_failure: always
before_install: sudo apt-get update -qq
script: make --directory "Var & ReadOnly C++"
And this is the associated makefile:
all:
$(CXX) -std=c++14 main.cpp -I . -Os -Wall -Wextra -o Example
clean:
rm Example*

g++: as fails to determine which assembler to run

Today I wanted to recompile one of my projects. Compiling this project had already worked on my machine, but this time an error occured.
The compiler output goes:
fatal error: as: unknown host architecture (can't determine which assembler to run)`
for the line:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../../.vscode -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I../../.vscode -I. -o Main.o ../../Main.cpp
I tried to compile some other projects, but realized, that I wouldn't be able to compile anything using any c++ compiler, so I looked it up.
The only fitting thread I found was this one but the solution 'reinstalling binutils' didn't work for me (tried sudo apt-get install --reinstall binutils as well as --reinstall gcc, g++ and build-essential)
One possible reason for this problem that comes to my mind is the iOS-toolchain I installed yesterday - I had to install some different clang versions - but I actually didn't change anything on the system's assembler...
If someone's got an idea; any help would be appreciated :)
Additional info:
Ubuntu 16.04 LTS 64bit
AMD FX(tm)-6300 Six-Core Processor × 6
uname -m
returns x86_64
gcc -march=native -v -E - 2>&1 <<<'' | grep "cc1" | egrep -o -e $'-m(arch|tune)=[^ "\']+'
returns -march=bdver2 and -mtune=bdver2
already tried gcc [...] -march with bdver2 and other architectures
g++ -v -c HelloWorld.cpp gives me: http://pastebin.com/Ks2be0hL
type -a as says:
as is /usr/local/bin/as
as is /usr/bin/as
as --version sadly just show's me the error again, but info as tells me it's binutils-2.26.1-system from 2016-08-07
dpkg -S /usr/bin/as prints: binutils: /usr/bin/as
type -a as says as is /usr/local/bin/as. This is what gcc is running, not /usr/bin/as, because /usr/local/bin/as is found first in your $PATH search order. This is why re-installing packages and so on is having no effect: something else you installed (probably manually) installed a non-standard as.
Have a look at /usr/local/bin/as and figure out where it came from, and what to do with it. For now you can just rename it to as.unknown or something, and then everything will use the normal system assembler (/usr/bin/as).
Remove binutils and reinstall it using the following steps:
Create an installation directory /opt/cross, and make sure you have write permission to .
sudo mkdir -p /opt/cross
sudo chown user /opt/cross
export PATH=/opt/cross/bin:$PATH
Download and install
wget http://mirrors.muzzy.it/gnu/binutils/binutils-2.9.tar.gz
tar xvf binutils-2.9.tar.gz
cd binutils-2.9
linux32 ./configure --prefix=/opt/cross --target=aarch64-linux --disable-multilib
If dosn't work remove --target=aarch64-linux, the --disable-multilib option means that we only want our Binutils installation to work with programs and libraries using the aarch64 instruction set, and not any related instruction sets such as aarch32, run:
linux32 ./configure --prefix=/opt/cross --disable-multilib
linux32 make
linux32 make install

libmysqlclient_18 not found

I'm trying to connect to mysql with C++ and the MySQLConnector, but I'm getting "undefined reference" errors everytime I make calls to the connector.
example:
/usr/lib/libmysqlcppconn.so: undefined reference to `mysql_stmt_execute#libmysqlclient_18'
My OS is Ubuntu 13.04 VM, I'm using Eclipse CDT and I installed the packages:
sudo apt-get mysql-client
sudo apt-get mysql-server
sudo apt-get mysql-client
sudo apt-get libmysqlclient-dev
I'm wondering that the libs (libmysqlclient,..) are in the folder /usr/lib/x86_64-linux-gnu/
and not in /user/local/mysql/lib like often found on the net. Does this make any difference?
I also downloaded the C++ Connector (binaries) from Oracle and copied the lib directory to /usr/lib and the include directory to /usr/include, but still I'm gettind the undefined reference errors.
I configured Eclipse in a way that I get this compile command:
g++ -L/usr/lib -L/usr/lib/x86_64-linux-gnu -pthread -o "Proj" ./Client.o -lmysqlcppconn -lmysqlclient -lz -lm -ldl
Any ideas?