I have a project written in c++ that I compile locally using g++ version 4.8.4 with following code
g++ BasicModel.cpp -std=c++11x -O3
I am trying to submit this file to a cluster to run large numbers of parallel simulations and to do this i need to compile the code on the cluster. g++ compiler on the cluster is out of data so i'm forced to use ICC compiler version 13.0.0
when run with the following
ICC BasicModel.cpp -O3
This however does not recognise lots of the c++11 syntax i've used. Are their flags i could use to avoid this or do i need to rewrite my code?
-std=c++11x is wrong it should be -std=c++11.
Related
I am trying to access std::popcount, but it seems like it's only there in C++ 20.
When I try compiling with g++ -std=c++20 main.cpp, it says g++: error: unrecognized command line option '-std=c++20'; did you mean '-std=c++03'
How do I tell g++ to use c++ 20?
I am using Ubuntu 18.04
C++20 features are available since GCC 8.
To enable C++20 support, add the command-line parameter
-std=c++20
For G++ 9 and earlier use
-std=c++2a
Or, to enable GNU extensions in addition to C++20 features, add
-std=gnu++20
I would try updating gcc. C++ 20 was introduced in gcc version 8 which is pretty new.
If it's an option you can update to Ubuntu 20.04 LTS which includes GCC version 9 out of the box. This would enable you to use C++ 20 and thus std::popcount
Note: use -std=c++2a in GCC 9 and earlier
there are different versions of the compiler exist and g++ is usually linked to the older one. for me, the current one is g++-9 and it clearly does not understand C++20.
C++20 requires installing gcc-10 and g++-10 (plus dependencies). assuming you already have them installed, then you need to run:
g++-10 -std=c++20 main.cpp
PS: if you want to go with v10 as default, then update links for gcc, g++ and other related ones, and use v9 (or whatever old you have) by full name.
EDIT: depending on the host OS, v11 and v12 could also be installed, but the naming is still important. replace with g++-11 or g++-12.
I am learning c++ and I am compiling lots of small programs without makefiles (using m-x compile) via g++.
When I want to compile according to c++14 I have to constantly add -std=c++14.
Is there a way to make g++ compile c++14 by default and avoid the extra typing?
Here is my current version:
g++ (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904.
Thank you.
I recently updated Ubuntu from 15.04 to 15.10. One of the major differences between these versions is the update of the default gcc version from gcc-4.9 -> gcc-5. The library I'm developing has been written and compiled for gcc-4.9, and relies on other libraries which only work in gcc-4.9.
I have installed gcc-4.9 onto my computer, and I can successfully compile both the library and my source file. However, when I tried to run the resultant program I get this error:
terminate called after throwing an instance of 'std::ios_base::failure[abi:cxx11]'
what(): basic_ios::clear: iostream error
Aborted (core dumped)`
The source code, and the file I'm trying to read here used to work before the upgrade. I have tried using the -D_GLIBCXX_USE_CXX11_ABI=0 flag, but I'm not sure this is the right thing to do, also it doesn't work.
This is an example of the flags I'm currently including in my makefile:
CPPFLAGS = -O0 -g3 -Wall -c -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++0x -fPIC -MMD -MP
Any ideas that might help me out?
You "simply" need to recompile everything your program needs that is C++.
See eg the Debian wiki on the transision which has (inter alia)
The good news is, that GCC 5 now provides a stable libcxx11 ABI, and stable support for C++11 (GCC version before 5 called this supported experimental). This required some changes in the libstdc++ ABI, and now libstdc++6 provides a dual ABI, the classic libcxx98 ABI, and the new libcxx11 (GCC 5 (<< 5.1.1-20) only provides the classic libcxx98 ABI). The bad news is that the (experimental) C++11 support in the classic libcxx98 ABI and the new stable libcxx11 ABIs are not compatible, and upstream doesn't provide an upgrade path except for rebuilding
There is no shortcut.
I have been using Armadillo 4.2 version (from linux mint package manager) for quite a some time. That version had no problem when compiled with icc, and codes compiled with icc ran very fast (about 10%-15% fast compared to g++).
Recently I have upgraded Armadillo to recent 6.1 version (from the official website). But in this case, all the codes compiled correctly with icc, but gave runtime error.
error: eig_sym(): failed to converge
terminate called after throwing an instance of 'std::runtime_error'
what(): eig_sym(): failed to converge
Aborted
Codes compiled correctly with g++ ran perfectly.
I have also tried previous 5.6 version, but the same problem.
Any solutions?? I had to revert back to old 4.2 version to get that extra speed from icc...
The Intel C++ compiler is known to contain of bugs when dealing with heavily templated libraries like Armadillo (see for example here and here).
You can increase the performance of gcc compiled code by enabling auto-vectorization (using -O3) and using the native machine instruction set (using -march=native). For example:
g++ code.cpp -o code -O3 -march=native -larmadillo
Also make sure that the matrix you're passing to eig_sym() is actually symmetric.
I've been trying to compile a multithread hello-world program under Cygwin using the newly introduced C++ 11 std::thread feature without success. I compiled and installed GCC 4.7.2 by myself, and the same code works without any problems under Linux with the same version of GCC. The first error I got was that the compiler did not recognize the -pthread flag. After researching on it for a while I noticed someone said on Cygwin this flag should be -lthread. I made the change and that error was gone, but another series of errors occur telling me thread is not member of std. I wonder if it's caused by the wrong configuration of the compiler during installation, or std::thread is simply not supported under Cygwin?
This looks like you did not compile the program with the appropriate standard library flag. If you want to compile for C++11 you should use:
g++ --std=c++0x -o ...
The --std flag sets the appropriate language compatibility level. If this does not help, please post the error messages you got as a source listing.