Reputation: 11
I am tring to compile and my C++ program on Linux using gcc command.
I used gcc -lm MyOwn.c Main.c -o Out
Myown.c
is another file I should link to the main.
The Out
file is successfully created.
The problem is Out
does not run.
When I tried to use gcc or cc to create exe file it gives me a lot of errors
Can someone help me?
Upvotes: 0
Views: 731
Reputation: 57076
Your problem may be that you're compiling as C code. Your files end with a ".c", and you are invoking gcc
. You should end the file name with ".cpp" or ".cc" or ".c++" or something else the compiler will recognize as C++.
You can also compile as C++ explicitly by typing g++
instead of gcc
.
Upvotes: 2
Reputation: 59347
The question is tagged C++. You say you're new c++. But the example you gave involve c code only.
gcc is used to compile c programs.
Use g++ instead.
C++ code files should have the suffix .cpp
or .c++
, but never .c
.
Fix those, try again, and edit the question to add the command line error if it still doesn't work.
Upvotes: 1