Monday, April 29, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 46006  / 2 Years ago, sun, june 5, 2022, 6:59:31

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.



helloworld.m



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:



Home>Documents>Objective-C>helloworld.m



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:



filedirectory



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:



terminal



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

More From » software-installation

 Answers
7

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
-D_NATIVE_OBJC_EXCEPTIONS

[#30087] Monday, June 6, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
utilitere

Total Points: 394
Total Questions: 110
Total Answers: 114

Location: Solomon Islands
Member since Wed, Mar 29, 2023
1 Year ago
;