Reputation: 43
I've used makefile to generate file. gcc -c hello.c -o hello and fixed the permission problem through: chmod a+x ./hello However, when I want to execute "hello" file. ./hello the system told me that "cannot execute binary file" Can someone help me? I am looking forward your reply badly.
Upvotes: 3
Views: 26604
Reputation: 449
Check whether the GCC compiler is installed in your system correctly or not.
gcc -v
Compile your file:
gcc filename.cpp -o any-name
Running your program:
./any-name
Upvotes: 2
Reputation: 19949
As an alternative to compiling and linking at the same time you can use make
:
make hello
Note: without the .c
extension.
The terminal output should be:
cc hello.c -o hello
Upvotes: 0
Reputation: 229088
The -c argument to gcc produces an object file which you later on must link in order to produce an executable. You can not execute the object file you produced.
Instead, to compile and link at the same time, suitable when you only have 1 .c file, do
gcc hello.c -o hello
Or if you want to break it down to separate compilation and linking steps, do
gcc -c hello.c -o hello.o
gcc hello.o -o hello
Upvotes: 8