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?
Try
chmod +x Out
./Out
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.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.