Home Ask Login Register

Developers Planet

Your answer is one click away!

Arturo February 2016

Run C++ executable on Linux

I am trying to compile an execute a C++ program in Linux using OpenCV.

When I type

g++ -c facedetection.cpp -std=c++11 -o facedetection

The facedetection file is correctly generated. Please note that I use -std=c++11 because I had an error advising to do so.

After doing chmod o+x facedetection I try to execute it with ./facedetection but I get error:

bash: ./facedetection: cannot execute binary file: Exec format error

What is wrong?


Chris Jester-Young February 2016

When you compile with -c, it generates an object (.o) file, not an executable. You need to compile it without -c in order to make an executable file.

Larger C++ programs will have more than one .cpp file; for each .cpp file, you would compile using -c to generate their respective .o file. Then you would link these .o files (running g++ without -c) to generate the final executable.

Post Status

Asked in February 2016
Viewed 2,963 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life