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'sCFile suffix.mThe header file suffix is.hFor 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 releasesLinuxCompileObjective-CThe command parameters are slightly different inDebianThe 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 ).DebianAnd 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~/.bashrcFile. Copy this command.bashrcAnd then execute:
source ~/.bashrc
Compile laterObjective-CThe file can use an alias.objccIt'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-CProgram example to illustrate, below is our routinemain.mContent:
#import <Foundation/Foundation.h>int main(int argc,const char * argv[]){ NSLog(@"hello world!"); return(0);}
Save the above Codemain.mAnd then execute:
objcc -o main main.m
The current directory will generatemain.
It must be noted that the executable file can only beDebianIf you wantDebianThe following part can be translated inOSXSome additional cross-compilation parameters are required for the executable file to run.