Cocoa with gcc command build without window
来源:互联网 发布:部落冲突极速升级数据 编辑:程序博客网 时间:2024/06/05 01:54
Cocoa with gcc command
这里介绍一下怎么开发最简单的Cocoa程序,这个程序是在是太简单,因为如果你用Xcode的话,选用Cocoa Foundation Command Tool的话,应该不用写任何代码, 但是这里是为了向大家介绍一下,这个最简单的程序是如何通过gcc编译成功的,当然里面还有一个东西可以做一点解释.
先看看源代码:
#import <Foundation/Foundation.h>
int main(int argc, char* argv[])
{
NSLog(@"Hello Cocoa From Console");
return 0;
}
代码很简单,你可以用你喜欢的任何文本编辑工具来完成它, 源码文件名为hello.m, 这样简单的一个程序用xcode的话就太奢侈了.
ok,下面来看看怎么编译这个程序, 打开终端, cd 到源文件所在的目录,然后执行下面的这个命令,就可以生成一个叫做hello的程序了.
gcc -framework Foundation hello.m -o hello
这 里面需要解释的是 -framework 参数, 熟悉gcc的朋友可能知道,gcc中的-l参数其实是传递给ld命令的,是用于链接器工作的, mac下面的-framework和-l参数的效果是一样的,就是告诉ld编译后的目标文件在生成最终的执行文件的时候,要连接哪个framework, 因为mac的核心Darwin也是一个unix,所以在Mac下面-l参数也是被支持的.
另外还有一点, gcc还可以接受-L来指定要连接的library在什么位置,这个选项一般用来连接第三方的库, 那么如果我想连接第三方的Framework的时候,我应该怎么做呢? -L /your/Framework? 不对, gcc针对这种情况使用了另外一个参数 -F, 所以如果你要连接第三方的framework, 比如/opt/Qt4/QtCore, 你应该像下面这样使用gcc.
gcc -F/opt/Qt4 -framework QtCore qttest.cpp -o qttest
好 了,现在继续来解释上面那个程序里面的另一个问题,为什么字符串的前面多了个@符号呢?想必这个东西也困扰了不少人, 在obj-c里面@"string"这种模式在编译的时候会被编译器进行一个转换,生成一个NSString指针的实例,所以在需要NSString指针 作为参数的地方,如果你不想明确的构造这个NSString指针, 那么用这种方法就最简单了,但是如果你将@"String"模式用在了需要c string的地方,就要出现错误了.
- Cocoa with gcc command build without window
- Cocoa with gcc command build 讲解一个简单的窗口程序
- How to build database on DB2 with db2 command
- Build Mini-XML DLL with Visual Studio Command Prompt
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1 解决方法
- error: command 'gcc' failed with exit status 1 的解决办法
- 【centos】 error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1
- error: command 'gcc' failed with exit status 1 的解决办法
- centos---error: command 'gcc' failed with exit status 1
- error: command ‘gcc’ failed with exit status 1
- error: command 'gcc' failed with exit status when installing psycopg2
- error: command 'gcc' failed with exit status 1
- 【centos】 error command 'gcc' failed with exit status 1
- AJAX 无法解析 & 等字符 问题
- Log4j简明手册(一)
- 使用LogKit进行日志操作
- 利用Struts结合Jbuilder7、MySql建立Web站点(1)--连
- One World, One Web——记第十七届万维网大会
- Cocoa with gcc command build without window
- XML在B/S架构开发中的应用
- SRM 397 DIV 2 [250]
- Sql常用函数语句
- win98下配置jsp的运行环境实践
- C#的面试题及答案
- 设计模式(Design Patterns)笔记之二:Adapter
- LVM创建和使用
- Jason Hunter采访