I am using c++ 11 i guess as per code::blocks. I was looking for a way to update to C++ 14. I found a way on one of the threads where it told me to add a flag in the compiler settings
-std=c++14
My default compiler is set to GNU GCC.
However after i tested a C++ 14 feature program it showed me the following error:
error: unrecognized command line option '-std=c++14'
Can anyone help me with this ? I was unable to find a solution online.
Also if what i did was wrong , is there any other way to switch to C++ 14?
Related
The full terminal output is as follows:
>g++ -std=c++98 -static mainP1.o -o mainP1
>
>ld: library not found for -lcrt0.o
>
>clang: error: linker command failed with exit code 1 (use -v to see invocation)
>
>make: *** [mainP1] Error 1
I'm on a 2020 MacBook Pro with an intel CPU using Visual Studio Code. When I write basic OOP programs in C++ it compiles fine without any clang errors. However, when working with big OOP programs with multiple classes inheriting from a base class I would get this error.
I tried searching online for solutions, but no solution or explanation was found. I double-checked my makefile to ensure I was not linking classes incorrectly.
I thought maybe I should just dual-boot with UBUNTU Linux to avoid this weird XCODE issue I was encountering with clang, but that was also a fruitless endeavor.
The problem was my compiler path in Visual Studio Code.
I changed it to clang++, and now all my code compiles and executes without any problems.
How I changed it:
CMD + SHIFT + P
Typed in: C/C++: Edit Configurations (UI)
Made sure that "Mac" was selected under configuration name.
Changed Compiler Path to: /usr/bin/clang++
I have started learning C++ on Ubuntu. I am only a few months into using Linux as well.
I am attempting to port over a 2D Ball Collision Script from Javascript to C++ for learning purposes.
I am using simple2D for the drawing in C++: https://github.com/simple2d/simple2d
I go to run this command:
simple2d build c-code-test.cpp
I receive this response:
cc1plus: warning: command line option ‘-std=c11’ is valid for C/ObjC but not for C++
/usr/bin/ld: /tmp/ccl07DBG.o: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev##GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Due to how fresh I am with Linux and C++ I am unable to make the correct inferences to solve this based on previous questions on stack overflow. I have installed libstdc++6 so I would have though it would be linked correctly.
Can someone walk me through in steps 1, 2, 3 ... Please? Thank you kindly!
The errors you see look to be from trying to compile C++ as C. The command line option is selecting the C11 standard, which is for C, not C++. The missing symbol is because the C++ library isn't being linked in, which also happens when linking a program as C.
I haven't used simple2d, but my guess here is that the compile script they wrote does not support C++ or there is some option you need to use C++. If we look at docs:
The simple2d build command is a helpful shortcut for compiling a
single source file. Of course, you can also use a compiler directly,
for example on Unix-like systems:
cc triangle.c `simple2d --libs` -o triangle
Why don't you try something like their example that invokes the compiler directly. But you would need to use g++ instead of cc. Something like: g++ c-code-test.cpp `simple2d --libs` -o c-code-test
This is a bug with the simple2d script.
They're basically using the wrong build command for C++.
You could work around it by patching in the fix I've linked to, or using the manual build step shown by TrentP.
Or wait for the next version after v1.1.0.
Recently, I am trying to compile a project with a dependency package called "dealii", but I keep getting this error when compiling:
g++: error: unrecognized command line option '-Wplacement-new'
It seems that g++ does not recognize the option -Wplacement-new. Then I looked at the documentation for gcc, it says -Wplacement-new is a legal warning option flag. But when I invoke "gcc -Wplacement-new ./a.c" I still get this kind of error.
My g++, etc are the latest version. Does anyone know how to fix it? Thanks
I've used CodeRunner (http://krillapps.com/coderunner) for a long time but recently I can't compile any C or C++ code in it. This started happening around the time I updated to Xcode 5.1. I can still compile and run as normal in Xcode.
When I try to run in CodeRunner, the following error is printed.
clang: error: unknown argument: '-finput-charset=UTF-8' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
There is already a solution for Objective C:
Clang error when compiling in CodeRunner
Does anyone know how to modify the script for C++/ C?
Thanks in advance.
There is a similar bug with the object-c compilation, the link to fix that is
Clang error when compiling in CodeRunner,
and you just need do as below for the c/c++ situation:
g++ "$1" -o "$compname" -finput-charset=${enc[$2]} $3
g++ "$1" -o "$compname" $3
I currently use C++ string properties and specifically its pop_back() fonction. As written in the title, it leads to an error (same error seen ini an other topic) :
‘std::string’ has no member named ‘pop_back’
But what's strange is that I already use C++11 specific properties (as "auto" for iterators, etc.) and I never get any error.
For information, I build my code under Ubuntu 12.04 with gcc 4.6.3. For me, this version is good enough. I also put "-std=c++0x" flag so I really don't know where is the point ?!
Moreover, I've seen, in previous topic, that it's better to use "-std=c++11" flag now. But when I try this, the following error appears :
unrecognized command line option ‘-std=c++11’
On gcc 4.6 (which had only partial support for the new standard) the option is -std=c++0x because at that time the release date (i.e., 2011) was still unknown.