Cocoa with GCC command build without window

Source: Internet
Author: User

Cocoa with GCC command

Here we will introduce how to develop the simplest cocoaProgramThis program is too simple, because if you use xcode and choose cocoa Foundation command tool, you do not need to write anyCodeBut here we want to introduce to you how the simplest program is compiled successfully through GCC. Of course, there is something in it that can be explained.

First lookSource code:
# Import <Foundation/Foundation. h>

int main (INT argc, char * argv [])
{< br> nslog (@ "Hello cocoa from console");
return 0;
}< br> the code is very simple. You can use any text editing tool you like to complete it. The source code file name is hello. m. It is too extravagant to use xcode for a simple program.
OK. Let's see how to compile the program, open the terminal, CD to the directory where the source file is located, and execute the following command to generate a program named hello.
gcc-framework Foundation hello. m-O hello
here we need to explain the-framework parameter. If you are familiar with GCC, you may know that the-l parameter in GCC is actually passed to the LD command, it is used for the work of the linker. The-framework and-l parameters under the Mac have the same effect, that is, after the LD is compiled The framework to connect to when the final execution file is generated for the target file. Because the Mac core Darwin is also a Unix, the-l parameter under MAC is also supported.
another point is that GCC can accept-L to specify the location of the library to be connected. This option is generally used to connect to a third-party library, so what should I do when I want to connect to a third-party framework? -L/your/framework? No. GCC uses another parameter-F in this case. If you want to connect to a third-party framework, such as/opt/qt4/qtcore, you should use GCC as follows.
gcc-F/opt/qt4-framework qtcore qttest. CPP-O qttest

now, let's continue to explain another problem in the above program. Why is there a @ symbol in front of the string? Presumably this thing has also plagued a lot of people. In obj-C, @ "string" will be converted by the compiler during compilation to generate an nsstring pointer instance, so where nsstring pointer is needed as a parameter, if you do not want to explicitly construct this nsstring pointer, this method is the easiest to use, however, if you use the @ "string" mode where C string is required, an error will occur.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.