HOWTO: Install GNUStep on FreeBSD & Compile Objective-C Code
Purpose:
If you've planning of doing Objective-C compiling on FreeBSD 9.1, then the following HOWTO will explain to setup and compile objective-C code up using the 'GNUStep' framework.
Note: This is a good introduction into programming objective-C programs on FreeBSD, afterward successfully getting your first app to compile, you will have to set out on learning more complex stuff on your own.
Assumptions:
1) Update ports
2) Install portupgrade
(Note: "DBATCH" makes it automatically select the default packages, I'm ok with that. If you are as well, leave it, else remove it and you will have to be on stand-by to select the options as they popup. If you left it and your computer is slow, go grab some tea/coffee/beer/etc. and do something else.)
3) Let's install the Objective-C 2.0 Runtime framework upgrade as this is the framework that you find on the Apple platform:
4) Install GNUstep:
(Note: The 'batch' works the same way with the portupgrade application. So if you have other things to do, feel free to leave the installation unattended.)
Now we need to set it up with our user.
Append the file with the following line:
Objective-C Compiling Steps:
5) Once the installation completes, we will have to confirm the code works. Lets create a temporary directory to run our code in:
6) Let's create our first application! The following was 'more then inspired' from the following link:
Populate the file with the following:
Ok, now lets create our make file:
Populate the file with the following:
Now we will compile our objective-c code:
The compiler should have made an 'obj' directory, now lets go into it and give permission to run everything inside:
Now lets run it! It should give get the 'First ObjC Program' message in the console:
GREAT! You should see a "First ObjC Program" in the console. You have written your first application. The next step is to read the manual from GNUstepand good luck with your learning. :stud
Note to Programmers:
Purpose:
If you've planning of doing Objective-C compiling on FreeBSD 9.1, then the following HOWTO will explain to setup and compile objective-C code up using the 'GNUStep' framework.
Note: This is a good introduction into programming objective-C programs on FreeBSD, afterward successfully getting your first app to compile, you will have to set out on learning more complex stuff on your own.
Assumptions:
- You are a novice/beginner with FreeBSD.
- You installed FreeBSD 9.1 from scratch with nothing else installed beforehand.
- You have basic/advanced knowledge of Objective-C programming.
- You program on a Apple Macintosh Computer using Xcode or something else and you're looking to port your code to FreeBSD.
- You are running FreeBSD 9.1.
1) Update ports
# portsnap fetch
# ports extract
# ports update
2) Install portupgrade
# cd /usr/ports/ports-mgmt/portupgrade
# make install -DBATCH clean
(Note: "DBATCH" makes it automatically select the default packages, I'm ok with that. If you are as well, leave it, else remove it and you will have to be on stand-by to select the options as they popup. If you left it and your computer is slow, go grab some tea/coffee/beer/etc. and do something else.)
3) Let's install the Objective-C 2.0 Runtime framework upgrade as this is the framework that you find on the Apple platform:
# portupgrade -N --batch libobjc2
4) Install GNUstep:
# portupgrade -N --batch gnustep
(Note: The 'batch' works the same way with the portupgrade application. So if you have other things to do, feel free to leave the installation unattended.)
Now we need to set it up with our user.
# vi ~/.profile
Append the file with the following line:
Code:
GNUSTEP_SYSTEM_TOOLS=/usr/local/GNUstep/System/Tools
export GNUSTEP_SYSTEM_TOOLS
Objective-C Compiling Steps:
5) Once the installation completes, we will have to confirm the code works. Lets create a temporary directory to run our code in:
# cd ~/
# mkdir testdir
# cd testdir
6) Let's create our first application! The following was 'more then inspired' from the following link:
# cat > example.m
Populate the file with the following:
Code:
:
#import <Foundation/Foundation.h>
int main( int argc, const char *argv[] ) {
NSLog (@"First ObjC Program");
return 0;
}
Ok, now lets create our make file:
# cat > GNUmakefile
Populate the file with the following:
Code:
GNUSTEP_MAKEFILES=/usr/local/GNUstep/System/Library/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = exampleapp
exampleapp_OBJC_FILES = example.m
include $(GNUSTEP_MAKEFILES)/tool.make
# gmake
The compiler should have made an 'obj' directory, now lets go into it and give permission to run everything inside:
# cd ./obj
# chmod 755 ./*
Now lets run it! It should give get the 'First ObjC Program' message in the console:
# ./exampleapp
GREAT! You should see a "First ObjC Program" in the console. You have written your first application. The next step is to read the manual from GNUstepand good luck with your learning. :stud
Note to Programmers:
- You can compile code which uses the "Grand Central Dispatch" framework. You simply have to install it through ports. (Reference: Link)
- Be mindful that there will be some functions that you find in Xcode missing in GNUStep.
- There are other Objective-C Run-time Frameworks available if GNUStep doesn't meet your requirements. Try CocoTron.