Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So here I have the basic "hello world" script for Objective-C, I have Ubuntu on my laptop and want to use Ubuntu to start compiling basic ideas, extra classes, or anything worth coding for any of my current projects on the go, so that way I can code a little bit wherever I am and not always have to be on my iMac.


Now my only question is how do I build and run this code in terminal? Obviously it's not that important since I'm coding for iOS and OSX so the only code that will display is anything that doesn't call on the SDK's or Cocoa scripts, so basically it should only display basic text commands such as "NSLog" or whatever, you get the just of what I'm trying to do, which is what I want. That way I can check for small errors at the very least.

I've looked around and I've found several helps for default shell scripts and such that call on the gcc directory or something of the sort from my understanding. I have created my own folder for Objective-C projects located in my documents and I had no idea if that is effecting my ability to run the file using the terminal commands that I've tried or not, but in case it is I store the projects in:


Also when running the command line:

gcc -o helloworld.m

or this

gcc -I/home/caseyerdmann/Documents/Objective-C/helloworld.m

or any version of that command line I receive this error:

gcc: fatal error: no input files
compilation terminated.

I believe I have all the compiler files installed but I am not opposed to a full tutorial, whatever gets this running. Now to clarify and gather a visual aid for you guys to try and help me better my text file is located in my documents:


And you can visually see the directory it is placed in. Now when I run any of the commands above that I have tried in terminal it yields this result:


It doesn't matter which command I use it is always that. I hope this helps a little bit more to provide an answer for my situation. I am not opposed to a full tutorial and having to save my file elsewhere or make any other changes by any means, in fact it'd be appreciated! I just would love to get this running.

I did some research and noticed the answers on this already are providing me with help to run the hello.m script that comes inside the GNUstep libraries, this is not what I am trying to do. However because I'm having trouble getting the default script to run I think I may have another problem as well, I'm going to continue researching to see if I can get that script to run, in the mean time any help is appreciated!

UPDATE: I have tried a new command and yielded a new result, though it was also unsuccessful in compiling I think it may help answer others to answer this. This is what I tried:

gcc -o helloworld.m -lobjc

and this was the result:

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
share|improve this question
Have you installed a Objective C compiler and compiled the code? – edwin Aug 3 '13 at 21:42
I have GNU Step installed but I'm not sure how to use it to compile the code, I only have it written in gedit and saved in objective-c format as helloworld.m in the directory listed. – Casey Aug 3 '13 at 22:10
The -o option is to specify the name of the executable to be produced (the default is a.out). You should write gcc helloworld.m -o HelloWorld -lobjc where HelloWorld is the name of the executable. – edwin Aug 6 '13 at 21:47
Oh okay, I understand now, however it still did not work. Maybe it's an error with GNUstep? I read something about having to make a shell script because gcc can't recognize where the file is? If so how to I do this? Or is that incorrect? – Casey Aug 6 '13 at 21:59
Please provide the output the command I put in the previous comment, also make sure you are on the right directory and your file is called helloworld.m – edwin Aug 6 '13 at 22:01

In Ubuntu 14.04 LTS, go ahead and install GNU objective-c compiler:

sudo apt-get install gobjc  

Verify the version:

gcc --version

must say something like:

gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Install GNUStep development libraries (equivalent to Cocoa on macosx):

sudo apt-get install gnustep-devel

It should work and compile with:

gcc HelloWorld.m `gnustep-config --objc-flags` `gnustep-config --base-libs` -o HelloWorld

You should run with:

share|improve this answer
up vote 2 down vote accepted

I did a little research and found a solution that works for now. I'll probably post a new question to see if there is a way to shorten this. But this successfully compiles my code. Thank you to everyone who provided some help, I definitely learned some new things.

gcc -o hello hello.m \
    -I `gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS` \
    -L `gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES` \
    -lgnustep-base -fconstant-string-class=NSConstantString \
share|improve this answer

You're missing the name for executable file. So, the command should be like:

gcc -o hello helloworld.m

After compilation, type


-o hello specifies the name of the output file you wish to create once the source is compiled. (In this case the output file name is hello.) This will create an executable file (named hello) which you, then, can run directly from the terminal. If you don't use -o option while compiling, the name of the executable file will be a.out by default. Now to execute that program, you need to type


The above commands assume you are already in the location of the source files, but both the source file and target output file may also be specified as a directory. For example:

gcc -o ~/Projects/hello ~/Desktop/hello.c

will compile a C source file located on your desktop and place the executable binary in a Projects folder in your home directory. To run this executable, type;


Or you can also first go to the directory where the source file is located and run above commands. You do not need specify pathnames if you're in the same directory where your source file is.

I'm wondering why your file extension is .m instead of .c.

share|improve this answer
That makes sense, however it did not work. I don't quite understand what that is calling for though, I understand GCC is my compiler/program I'm using to run my code in termianl, but what directory is "-o" calling on and why is "hello" needed before helloworld.m when it is not anywhere in my file or related to it. And while the executable file name being needed makes sense, I don't actually have one It's just a text file typed in gedit saved in objective-c format. I'll try and update my question to be more descriptive of my problem to see if that yields a better result. – Casey Aug 6 '13 at 20:36
man gcc will output the manual pages for gcc. I suggest you do some reading. "-o foobar" simply says output a file named foobar, instead of the default, which is a.out. – ubfan1 Aug 6 '13 at 21:41
gcc -o hello hello.m

should produce the objective c executable if the compiler is installed. If not, install it:

sudo apt-get install gobjc
share|improve this answer
The result of running the first command, which i tweaked to use the correct file name of my project, ended in this result: gcc: fatal error: no input files compilation terminated. I also checked to see if gobjc was installed by running the second command, and it is in fact installed. Am I missing anything else? – Casey Aug 5 '13 at 1:45
Sounds like you used the wrong file name. Did you get the case correct and don't have any nasty things like spaces in the name? – ubfan1 Aug 5 '13 at 4:55
well I used your exact command at first but then I realized that my file name isn't hello.m so I entered this exactly: "gcc -o helloworld.m" However, my file is located in my documents, I feel like there’s a line I'm missing to help locate the file in my documents I just don't know what the command is. – Casey Aug 6 '13 at 19:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.