Issue running c++ file -- Input/output error - c++

I have some C++ code that has been running fine for a long time now. I just upgraded my Mac to macOS Catalina and now about 50% of the time when I compile, it runs fine and 50% of the time when I compile and then run I get
sh: ./file: Input/output error
I can compile no problem. The issue is on executing the file.
I'm compiling with g++ -std=c++11 -I ext/ file.cpp -o file -ffast-math -O3 -DEIGEN_STACK_ALLOCATION_LIMIT=0
I have no idea what's going on or how to fix this. I can run everything else seemingly fine.
EDIT
When I run ls -l I get
-rwxr-xr-x 1 NAME staff 12872 Feb 27 15:21 ./file
And file ./file returns
./compilation_tests/runnable_c_files/3D_P1_non_zero/1/3D_P1_non_zero2: Mach-O 64-bit executable x86_64
The really weird thing is that now when I run the first time I get the same Input/output error. However, no matter what, the second time I run it goes perfectly. Further, if I recompile, it works the first time I run.
BUT...when I put this into a python script (using os.system to run shell commands) it never works. I need to compile and run twice from my terminal.
EDIT #2
I've run a simple hello world and am encountering the same bug. The code is:
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
cout << "Hello world!" << endl;
return 0;
}
I compile with g++ -std=c++11 test.cpp -o test -ffast-math -O3 -DEIGEN_STACK_ALLOCATION_LIMIT=0 and permutations thereof (mixing flags etc).
And about 50% of the time I am getting the same error. Is this just a hardware issue?
I have no clue what's going on.

Related

VS code c++ debugger setup using GDB does not work

So here's my problem. I have downloaded mingw g++ by using msys according to the official vs code website
Here are my files:
Now, when I try to build I get this error:
> Executing task: g++ -std=c++14 -g -o myfile.exe myfile.cpp <
cc1plus.exe: fatal error: myfile.cpp: No such file or directory
compilation terminated.
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command g++ -std=c++14 -g -o myfile.exe myfile.cpp" terminated with exit code: 1.
And if I do have a .exe file:
edit: I also started getting errors with
#include <iostream>
I would make this a comment if I could. What is the name of the file where you have written #include <iostream>?* I think if you change the name of that file to "myfile.cpp", you might stop getting that error. You will probably get a different error saying that "main() cannot be found" or something like that, but that's an improvement from your current spot.
*I see it's O3.cpp. Try changing that to myfile.cpp.

Why do I get "does not name a type" when compiling my hello world c++ file

After updating my Arch Linux system on my laptop, I ran into a lot of compilation errors when trying to compile the project I am working on. The same code compiles well on other machines.
So, I tried a little hello world program, and it fails with the same error.
I have spent quite some time trying to figure out what is happening, but I get nowhere, so I would very much appreciate any hints.
The file I try to compile is very simple:
#include <iostream>
int main ()
{
std::cout << "Hello, world!\n";
return 0;
}
I compile it like this:
$ g++ -Wall -Wfatal-errors hello.cpp -o hello
And get the following error:
In file included from /usr/include/c++/8.2.1/memory:74,
from /usr/local/include/format.h:36,
from /usr/local/include/time.h:11,
from /usr/include/pthread.h:24,
from /usr/include/c++/8.2.1/x86_64-pc-linux-gnu/bits/gthr-default.h:35,
from /usr/include/c++/8.2.1/x86_64-pc-linux-gnu/bits/gthr.h:148,
from /usr/include/c++/8.2.1/ext/atomicity.h:35,
from /usr/include/c++/8.2.1/bits/ios_base.h:39,
from /usr/include/c++/8.2.1/ios:42,
from /usr/include/c++/8.2.1/ostream:38,
from /usr/include/c++/8.2.1/iostream:39,
from hello.cpp:4:
/usr/include/c++/8.2.1/ext/concurrence.h:124:5: error:
'__gthread_mutex_t' does not name a type; did you mean
'__pthread_mutex_s'?
__gthread_mutex_t _M_mutex;
^~~~~~~~~~~~~~~~~
__pthread_mutex_s
compilation terminated due to -Wfatal-errors
If I remove the -Wfatal-errors switch, I just get tons of more errors.
It was the two header files in /usr/local/include, i.e. format.h and time.h that was the cause of my problems. After removing them I am now able to compile my project again.

C++ code compiles, but shows an error when running on Zorin OS

I'm learning C++ and trying to run a simple hello world program. It compiles but it won't execute. It worked on Windows, but it won't run on Zorin OS.
I read online that the command to run it is ./test or ./test.exe.
This is what is looks like on the terminal:
$ g++ test.cpp -o test.exe
$ ./test
bash: ./test: No such file or directory
I looked at the questions similar to this, but none have helped me.
You can not expect to be able to execute the same commands on both Windows and Linux. They use different shells with different syntax and different behaviors.
Here's a typical example of compiling a file on GNU/Linux:
dir$ g++ myfile.cpp -o myfile
dir$ ./myfile
Here's a typical example of compiling the same file on Windows:
dir> g++ myfile.cpp -o myfile.exe
dir> myfile
Note in particular:
Linux doesn't use .exe or other extensions on executables, but Windows does.
Windows doesn't require specifying directory to run files in the working directory, but Bash on GNU/Linux generally does.
The only reason why the compilation command is as similar as it is is that g++ is a Unix tool ported to both platforms. Windows normally uses / instead of - for flags like -o
As commands get more complex, they start diverging even further.

Exec Format Error Eclipse CDT

I have a basic C++ program in Eclipse CDT:
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello World!";
}
However, when I try to build it, I get an Exec Format Error. Here is the output produced by the compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o hey.o "..\\hey.cpp"
g++: error: spawn: Exec format error
I am using MinGW Toolchain. I am on 64-bit Windows, and I think that may have something to do with it. Would anyone know how to get this program running?
Edit
Running the exact command in command prompt in the directory where my source file is works just fine, without throwing errors, but it still doesn't work in Eclipse
So, I have fixed this myself by installing the 64-bit version of MinGW (http://sourceforge.net/projects/mingw-w64/). It now compiles and builds noramlly

Eclipse c++ build error: no such file or directory

I installed MinGW and CDT following some tutorials. I'm trying to compile and run "hello world" code. There are no errors in eclipse but when I compile the code I get this error:
22:48:32 **** Incremental Build of configuration Debug for project test3 ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++\\mingw32" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\test3.o" "..\\src\\test3.cpp"
g++: error: CreateProcess: No such file or directory
22:48:32 Build Finished (took 135ms)
The code:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Might be a silly question to ask, but did you save the file somewhere before building it? I've had an error like this that was solved by saving it on my Desktop or wherever.
Edit: There seems to be several people with problems using MinGW. You mentioned you looked at previous stackoverflow questions, do they include these:
Eclipse CDT error: Unable to compile
MinGW error: No such file or directory exists
Other solutions suggest you should try compiling the program via command line, which...shouldn't be a problem since it's just "Hello, World".