0

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
  • 7
    What "does not run"? What output do you get when you run your gcc command? Commented Sep 20, 2010 at 20:27
  • 1
    What's the output put of: file Out Commented Sep 20, 2010 at 20:29
  • 8
    By the way, if it really is C++ code, you should use g++ instead of gcc. Commented Sep 20, 2010 at 20:33
  • 3
    This is not a good question, since you provide no clue as to what the errors are. Commented Sep 20, 2010 at 22:01

3 Answers 3

4

Try

chmod +x Out
./Out
Sign up to request clarification or add additional context in comments.

1 Comment

Correct, but sometimes things happen when one fiddles with files :)
2

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.

Comments

1

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.

2 Comments

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).
I purposely omitted .C. It's about as useful as a trigraph. Though .cc is common enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.