#include <cstdatomic> "no such file" in ubuntu - c++

when compile with g++ -std=c++0x -Wall test.cc -o hello,
output fatal error: cstdatomic No such file or directly
Where is missing?

The include should be #include <atomic>

Related

g++ won't compile very simple program using threads

Attempting to use threads in C++ for the first time. Here is my code:
#include <iostream>
#include <thread>
int main(){
std::thread th;
}
To compile, I am using:
g++ -g -Wall -std=c++11 -pthread threadtest.cpp
This gives the following error:
$ g++ -g -Wall -std=c++11 -pthread threadtest.cpp
threadtest.cpp: In function 'int main()':
threadtest.cpp:5:8: error: 'thread' is not a member of 'std'
5 | std::thread th;
| ^~~~~~
threadtest.cpp:3:1: note: 'std::thread' is defined in header '<thread>'; did you forget to
'#include <thread>'?
2 | #include <thread>
+++ |+#include <thread>
3 |
If I comment out the "std::thread th" line, the error message changes to:
$ g++ -g -Wall -std=c++11 -pthread threadtest.cpp
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
Operating system: Windows 10. Seems to get the same result whether I'm using the plane-old windows command line or if I do it in Cygwin. Anyone know what's wrong? Thanks in advance.

g++: fatal error: no imput files linux

I'm trying to compile on linux mint shell the following cpp file:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello"<<endl;
return 0;
}
the most basic program possible since I just wanted to test compiling on shell
I tiped:
g++ -o hello.cpp hello
and as a result:
g++: error: hello: no such file or directory
g++: fatal error: no imput files
compilation terminated
what did I do wrong?
It's:
g++ -o hello hello.cpp
The -o indicates the desired name of the output file

Code compiles with g++ 5.2.1 but not with g++ 4.9.3

Why this code compiles using g++ 5.2.1, but fails with g++ 4.9.3?
//exception.h
class MyError: public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
// nothing else here
//main.cpp
#include <iostream>
#include "exception.h"
int main() {}
5.2.1 compilation:
$ g++ --version
g++ 5.2.1
$ g++ -std=c++11 -c main.cpp -o main.o
$ g++ main.o -o a.out
Compilation successfull.
4.9.3 compilation:
$ g++ --version
g++ 4.9.3
$ g++ -std=c++11 -c main.cpp -o main.o
$ g++ main.o -o a.out
In file included from main.cpp:2:0:
exception.h:3:1: error: expected class-name before ‘{’ token
{
^
exception.h:5:14: error: ‘std::runtime_error’ has not been declared
using std::runtime_error::runtime_error;
....
Solution is to add #include <stdexcept> to exception.h
Now it works with both versions.
When I remove #include <iostream> from main.cpp, then compilation fails even with 5.2.1 version and #include <stdexcept> is required too.
Why this code works on 5.2.1 version without including stdexcept header?
It's included in iostream on 5.2.1 version but not in 4.9.3 version? Reading GCC changes didn't help.
The standard library headers are allowed to include other headers, but there are no guarantees.
Back in the ancient days of g++ 4.0 and 4.1, you could pull in most of the standard library with just #include <iostream> and #include <deque>. But that stopped working in version 4.3 (or something like that).
In order for your code to be portable it should explicitly include all the required headers.

installing ddd - fatal error

So I have been trying to install DDD. I am on a Mac OS X 10.9(Mavericks) and I have the latest Xcode installed. Whenever I run my configure file the last thing I get is the following:
checking whether c++ accepts -g... yes
checking whether the C++ compiler (c++) compiles a simple program... no
configure: error: You must set the environment variable CXX to a working
C++ compiler. Also check the CXXFLAGS settings.
See the file 'config.log' for further diagnostics.
and whenever I check the config.log file I get:
configure:2684: c++ -o conftest -g -O2 conftest.C 1>&5
configure:2678:10: fatal error: 'iostream.h' file not found #include <iostream.h>
1 error generated.
configure: failed program was:
#line 2677 "configure"
#include "confdefs.h"
#include <iostream.h>
int main() {
cout << "hello, world!";
; return 0; }
I have downloaded the gcc from sourcefourge and installed gcc-4.9 again, but I still getting the same error. Anybody knows how to fix this or what the problem maybe?
It seems like you are compiling c++ program but you passing .c file to c++ compiler. You passing conftest.c file to c++ compiler, it has to be confest.cpp.
configure:2684: c++ -o conftest -g -O2 conftest.C 1>&5
This has to be
configure:2684: c++ -o conftest -g -O2 conftest.cpp 1>&5
And
fatal error: 'iostream.h' file not found #include <iostream.h>
1 error generated.
For above error change your code
to #included <iostream>
instead of #include <iostream.h>
Just open you configure file in DDD directory and add the following
`<iostream>
using namespace std;
`
and that should solve this error

atomic_thread_fence is not a member of std

Compiling with:
g++ -std=c++0x -Wall -pthread test2.cc -o hello
I'm getting this error:
test2.cc: atomic_thread_fence is not a member of std
I am using g++ 4.5.2 in Ubuntu. What am I missing?
Do you have the following in test2.cc?
#include <atomic>