Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Clang: Error: No Such File or Directory

Hello Mac Communities,

I have recently installed Xcode 6.1.1, but currently just want to compile C files. I would like some help with a rather irritating error.


Here are the commands I try and their results.

command: gcc -c /Users/(my username)/Documents/C/helloworlddot1.c

result: error: no such file or directory: filename.c


or, after filename is changed to helloworld00.c;


command: ]gcc -c /Users/(my username)/Documents/c/helloworld00.c

result: (no text is displayed) The file helloworld00.o is created


That seemed to work for the moment, until I tried to compile/convert the machine code into a program:

command: gcc -c /Users/(my username)/Documents/c/helloworld00.o

result: clang: error: no input files


...which is weird.


Can anyone help with this?


P.S. Is this the best community to post this type of thing to?

MacBook Pro, OS X Yosemite (10.10.1), null

Posted on Jan 24, 2015 5:31 PM

Reply
Question marked as Best reply

Posted on Jan 24, 2015 6:00 PM

You can work entirely in Xcode by using the command-line tool template in C. Xcode > File > New > Project > Command-Line Tool > Next > Language: C > Next > Create.


If you do want to work on the command line, you may as well just use the "clang" program instead. The "gcc" tool is just a compatibility tool for existing scripts that are expecting the actual "gcc" program. Apple hasn't used the real "gcc" for years. (Read up on the GPLv3 for more information.)


The gcc/clang arguments are the same. The "-c" flag instructs the compiler to only compile a single .c file into a .o object file. It won't create an executable. If you are only compiling a single source file, just omit the "-c" flag and the compiler will create an executable named "a.out" that you can run by typing "./a.out". You can specify "-o <executable name>" if you want to specify a name. Once you get more than a handful of source files, using the terminal starts to become a hassle. At that point, you definitely want to start using Xcode.


I'm not sure why you would try to compile "helloworlddot1.c" and then get an error message about "filename.c". Something else is wrong.


If you are working in the Terminal, it is easiest to use the "cd" command to move into the same directory as your source files. Then you don't have to keep typing the full path.


It is hard to say what the "best" community is. There are many to choose from.

3 replies
Question marked as Best reply

Jan 24, 2015 6:00 PM in response to Lvk3

You can work entirely in Xcode by using the command-line tool template in C. Xcode > File > New > Project > Command-Line Tool > Next > Language: C > Next > Create.


If you do want to work on the command line, you may as well just use the "clang" program instead. The "gcc" tool is just a compatibility tool for existing scripts that are expecting the actual "gcc" program. Apple hasn't used the real "gcc" for years. (Read up on the GPLv3 for more information.)


The gcc/clang arguments are the same. The "-c" flag instructs the compiler to only compile a single .c file into a .o object file. It won't create an executable. If you are only compiling a single source file, just omit the "-c" flag and the compiler will create an executable named "a.out" that you can run by typing "./a.out". You can specify "-o <executable name>" if you want to specify a name. Once you get more than a handful of source files, using the terminal starts to become a hassle. At that point, you definitely want to start using Xcode.


I'm not sure why you would try to compile "helloworlddot1.c" and then get an error message about "filename.c". Something else is wrong.


If you are working in the Terminal, it is easiest to use the "cd" command to move into the same directory as your source files. Then you don't have to keep typing the full path.


It is hard to say what the "best" community is. There are many to choose from.

Clang: Error: No Such File or Directory

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.