How do I write and compile Objective-C code?

2020-06-09 06:49发布

问题:

How do I write and compile Objective-C code in Linux?

I heard about Clang, but I couldn't find any example/tutorial about Clang/LLVM/Objective-C.

回答1:

sudo apt-get install build-essential gobjc gobjc++ gnustep gnustep-devel libgnustep-base-dev -y
vi *.m
gcc `gnustep-config --objc-flags` *.m -lgnustep-base -lobjc


回答2:

You download and build LLVM as the compiler infrastructure; then you download and build the CLANG front-end to compile C/C++ and Objective C/C++.

I guess you could try following this quick start guide. Mind that Clang could actually replace GCC when working with these languages.



回答3:

Take a look at http://www.gnustep.org/ they have tools for developing with Objective-C 2.0 for LINUX. The source files and hints on how to install it on several LINUX distros are here: http://www.gnustep.org/resources/sources.html



回答4:

Just run the following script shown on this page:

https://gist.github.com/nicerobot/5652802

Pay attention: During the first compiling process you will get an error. Solution is just to recompile it... It works !!! Here is the blog entry from the step by step installation but I really recommend the script!

http://blog.tlensing.org/2013/02/24/objective-c-on-linux-setting-up-gnustep-clang-llvm-objective-c-2-0-blocks-runtime-gcd-on-ubuntu-12-04/#comment-54284

regards