1

I'm trying to execute via command line a code written in C. I tried gcc -o file file.c, but it did not work. I need to learn how to compile and execute a code using gcc and llvm without graphical interface. Furthermore when I compile the program I cannot find the executable file in Finder (there's no Developer folder in Library).

Thanks in advance.

user1286390
  • 101
  • 1
  • 2
  • 6

2 Answers2

2

You can use xcrun tool:

#/usr/bin/xcrun cc -o file file.c

Note: if you have several Xcode versions you can chose with xcode-select and your command above will use compiler and the rest of the tools from the selected SDK.

vvlevchenko
  • 884
  • 7
  • 5
1

If file.c is in the Desktop directory: Did you change to that directory beforehand?

Usually Terminal.app starts in the home directory, e.g.: /Users/yourname

To get to the Desktop directory:

cd ~/Desktop

Then check if the source file is there:

ls -l file.c

Then try again to compile:

gcc -o file file.c

Check for any error messages. If no output is given everything is fine and there should be an executable which can be (surprise!) executed:

ls -l file
 ./file
zoliton
  • 191
  • 5