• C

How do I compile a simple C program using Terminal on a mac?

I used Filezilla to upload a file called main.c to a server that has the gcc 4.4.7 package installed on it. My teacher gave the following instructions in bold below. But I can't seem to run the main.c program without getting several "No such file or directory" messages. For example, I tried typing "gcc main.c –o main.out" and it did not work. I just want to be able to view the output of a "hello world" program in Terminal.

Basic syntax of a compile: gcc programname.c –o nameofexecutable.out
Execute the program by entering nameofexecutable.out from the command-line
shampouyaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
"gcc main.c o main.out"
used a character.  It should be a - character
the command should be
gcc main.c -o main.out
instead of
gcc main.c –o main.out
0
shampouyaAuthor Commented:
I just tried this below and nothing happened

gcc main.c -o main.out
main.out
0
ozoCommented:
What was in main.c?
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Dave BaldwinFixer of ProblemsCommented:
Apple Macs do not come with 'gcc' installed, you have to do it yourself.  Here's an article that describes a number of the issues with that: https://blog.udemy.com/c-compiler-for-mac/
0
jmcgOwnerCommented:
I just tried this below and nothing happened

gcc main.c -o main.out
main.out

If nothing happened, i.e. no warning messages, then things are pretty close to working. The gcc command is installed and available in your shell's PATH and it appears to have produced a "main.out" file or else that line would have caused a message as well.

If the main.c that you compiled contained syntactically correct code that just doesn't happen to do anything visible, this is exactly what you would see. Try again with a HelloWorld.c program:

#include <stdio.h>
 
int main()
{
    printf("Hello, world!\n");
}

Open in new window


[For more examples in other languages, see the List of Hello world program examples Wikipedia article.]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shampouyaAuthor Commented:
Thank you so much, very valuable insight! I think I was missing my main method. Once I added that, I could see the output in terminal.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.