tags:

views:

144

answers:

4

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?

+4  A: 

Try

chmod +x Out
./Out
jlafay
By the way, Out should be already chmodded correctly.
Matteo Italia
Correct, but sometimes things happen when one fiddles with files :)
jlafay
+2  A: 

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.

caspin
Sometimes, also .C (uppercase C) is used (which is recognized by g++), although it's not recommended, since it's not portable on case-insensitive systems (and it's also more difficult to catch at glance).
Matteo Italia
I purposely omitted `.C`. It's about as useful as a trigraph. Though `.cc` is common enough.
caspin
+2  A: 

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.

David Thornley
A: 

thank alot it works when i tried ./out but all your answers were usefull for me to learn new about linux thanks

Olfat