Build the objective-C compiling environment directory under the dragon core 8089d-debian7
- Install Related Files
- Compilation parameter description
- Simplify command line parameters
- Actual compilation instance
Simple Description: Objective-C'sC
File suffix.m
The header file suffix is.h
For example, the routine in this tutorial ismain.m
.
Install Related Files
Install these packages:gcc
,g++
,gobjc
,gnustep
,gnustep-devel
,gnustep-gui-dev
,libgnustep-base-dev
.
The installation command is simple:
apt-get install gcc g++ gobjc gnustep gnustep-devel gnustep-gui-dev libgnustep-base-dev
After installation, you can proceed to the next step.
Compilation parameter description
For different releasesLinux
CompileObjective-C
The command parameters are slightly different inDebian
The following parameters are required:
`gnustep-config --objc-flags`-fconstant-string-class=NSConstantString-lobjc-lgnustep-base
In addition, you must specify the location of the header file (include file) and library file (LIB file ).Debian
And their positions are/usr/include/GNUstep/
And/usr/lib/GNUstep/
The parameters are as follows:
-I /usr/include/GNUstep/-L /usr/lib/GNUstep/
The compilation command that combines the above parameters is as follows:
gcc `gnustep-config --objc-flags` -fconstant-string-class=NSConstantString -lobjc -lgnustep-base -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -o main main.m
However, every time you input so many parameters, it is a little complicated. Next we will create an alias for this long string of commands.alias
Simplify command line parameters
The command to create an alias is as follows:
alias objcc=‘gcc `gnustep-config --objc-flags` -fconstant-string-class=NSConstantString -lobjc -lgnustep-base -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/‘
To save this command to the System~/.bashrc
File. Copy this command.bashrc
And then execute:
source ~/.bashrc
Compile laterObjective-C
The file can use an alias.objcc
It's easy:
objcc -o main main.m
Note: In this alias commandSingle quotes:
''AndReverse quotation marks:
''Do not confuse.
Actual compilation instance
Finally, it is based on an actualObjective-C
Program example to illustrate, below is our routinemain.m
Content:
#import <Foundation/Foundation.h>int main(int argc,const char * argv[]){ NSLog(@"hello world!"); return(0);}
Save the above Codemain.m
And then execute:
objcc -o main main.m
The current directory will generatemain
.
It must be noted that the executable file can only beDebian
If you wantDebian
The following part can be translated inOSX
Some additional cross-compilation parameters are required for the executable file to run.