ArticleDirectory
- Install
- Development
- Run
- Make
- Reference
I am also a black apple family. The reasons for not buying Mac are different. Even if it is installed with a black apple, you need to work on windows for a long time and want to be unable to get an OC compiling environment on windows, so that you can easily learn OC and save the time to switch back and forth.
Most of the content in this article is from the Internet. For details, refer to the reference section. This article is obtained by the author after practical use. If you have any omissions, please kindly advise. Thank you.
Install
I searched the internet and found a lot of information in this regard. The necessary stuff is gnustep developer tools. You can refer to this link for Windows Installer. The installation is very simple, install gnustep system, gnustep core, and gnustep developer in sequence. The process is not described.
After the installation is complete, we can use"Program-> Gnustep-> shell "to start a simulated UNIX console, where you can complete development, compilation, and execution.
Development
First, write a helloworld file. For simplicity, create a helloworld. M file in the root directory of drive C and save it,CodeAs follows:
[CPP] View plaincopy
-
- # Import <Foundation/Foundation. h>
-
- IntMain (IntArgc,Const Char* Argv [])
-
- {
-
- NSAID utoreleasepool * Pool = [[NSAID utoreleasepool alloc] init];
-
- Nslog (@"Hello world! ");
-
- [Pool drain];
-
-
- Return0;
- }
Note: As I was the first time to use the tool to write code, I did not recommend a very good tool. I used ultraedit myself.
Compile
Because helloworld. m is under the C root directory, we should first switch the path to the C root directory:
[Plain] View plaincopy
- $ Cd c :\
Note: CD is also applicable to switching to any drive or any subdirectory. The path structure is no different from that of windows, and is case insensitive.
Compile to target code
[Plain] View plaincopy
- Gcc-fconstant-string-class = nsconstantstring-C helloworld. M-I/gnustep/system/library/Headers
After the preceding command is executed, the console does not have any output. This is correct; otherwise, you need to check the cause. At the same time, a target file helloworld. O will be generated under the C-drive root directory. In the next step, we will use it to compile it into an executable file.
Compile to an executable file
[Plain] View plaincopy
- Gcc-O helloworld. O-L/gnustep/system/library/libraries/-lobjc-lgnustep-Base
Helloworld.exe is generated in the C root directory.
Run
You can run helloworld.exe directly on the Windows console or in the shell window:
In the shell window, enter:
[Plain] View plaincopy
- ./Helloworld.exe
The output is as follows:
[Plain] View plaincopy
- 13:22:42. 828 helloworld [5484] Hello world!
About work path
During development, the project cannot be stored in the C-drive root directory, which is generally organized. How can we compile such files? In fact, the method is very simple. Use the CD command to enter the directory where. m is located, and then execute the compilation.
Make
The above compilation process is very cumbersome. If you accidentally enter an error, the compilation may fail. In fact, another simpler method is to create a make file. For gnustep, the make file name must be "gnumakefile" with the following content:
[HTML] View plaincopy
- Include $ (gnustep_makefiles)/common. Make
- Tool_name=Helloworld<Strong>
- </Strong>Helloworld_objc_files=Helloworld. M
- Include $ (gnustep_makefiles)/tool. Make
The helloworld keyword is replaced with the actual content. Gnumakefile must be in the same directory as the. M file.
Make is easy to execute. Go to the directory where gnumakefile is located and execute make in the shell window. This will generate an OBJ directory in the directory where gnumakefile is located. OBJ contains executable files and target files.
Postscript
Simply put, there are basically no twists and turns, that is, the problem of working path is annoying, because someone said there will be a"C: \ gnustep \ home \ Username"Directory, but I didn't have similar things after installation. Maybe the version is inconsistent or why? This is no longer a problem.
Note: The problem above is as follows. Later I found that this home still exists. after starting the shell, enter the PWD command to get the current working path:/home/username. The actual location is"D: \ gnustep \ msys \ 1.0 \ home \ Username".
Reference
- Objective-C: GCC + gnustep configuration-rabbit pumpkin eating
- Compile objective-C in Windows