在Mac OS X上安装Xcode以及编译Objective-C

Mac OS X 安装 OpenCV2.4.3【详述】 最近给MacBook装OpenCV走了很多弯路,读了很多帖子和Blog,但感觉都和我遇到的情况有些不同,他们的博客也写的很简略,所以出于以上几点原因加上想做一下备忘,写了这篇很详细很冗长的Blog。 --------------------------------------------------------------------------------------------------- 阅读详情
 

In later chapters we will look at how to install and use Objective-C on Windows and Linux systems for those that do not have access to Mac OS X. If you are planning to develop iPhone applications (or Mac OS X applications for that matter), however, you are going to need to use an Intel based Mac OS X system at some point in the future.

Perhaps the biggest advantage of using Mac OS X as your Objective-C learning platform (aside from the ability to develop iPhone and Mac OS X applications) is the fact that you get to use Apple's Xcode development tool. Xcode is a powerful and easy to use development environment that is available free of charge to anyone fortunate enough to own an Apple computer running Mac OS X.

In this chapter we will cover the steps involved in installing Xcode and writing and compiling a simple Objective-C program in this environment. For those readers that prefer to do their coding and compiling at the command prompt we will then cover use of Objective-C in a terminal window.

Contents

[hide]
Installing Xcode on Mac OS X

Xcode may or may not be pre-installed on your Mac OS X system. To find out if you already have it, open the Finder and look for it in theDeveloper subfolder of the Applications folder. If the Developer folder does not exist, or does not contain Xcode then you will need to install it.

The best way to obtain Xcode is to download it from the Apple web site. It can also be installed from the Developer Tools installation disk if you happen to have one, but most Mac systems do not ship with this. The URL to download Xcode ishttp://developer.apple.com/technology/xcode.html. There are two forms of Xcode, one for developing both Mac OS X and iPhone applications and the other solely for developing Mac OS X applications. In order to download Xcode, you will need either a Registered iPhone Developer account (in the case of the iphone Xcode) or an ADC membership (in the case of the Mac OS X Xcode). Fortunately, both of these memberships are free and can be activated using your existing Apple account (for example the one you use to buy music on iTunes).

Once you have registered, you will gain access to the Apple Developer Connection web site where download links are provided for Xcode on a variety of Mac OS X versions.

The download is over 2GB in size and will take a number of hours to complete depending on the speed of your internet connection. The package takes the form of a disk image (.dmg) file. Once the download has completed, a new window will open as follows displaying the contents of the .dmg file:

The iPhone SDK .dmg contents


If this window does not open by default, it can be opened by clicking on the SDK disk drive icon on the desktop.

Initiate the installation by double clicking on the package icon (the one that looks like an opening box) and follow the instructions until you reach theCustom Install screen:


Selecting the iPhone SDK components to install


The default selections on this screen are adequate for most requirements so unless you have specific needs there is no need to alter these selections. Continue to the next screen, review the information and clickInstall to begin the installation. Note that you may first be prompted to enter your password as a security precaution. The duration of the installation process will vary depending on the speed and current load on the computer, but typically completes in 15 - 30 minutes.

Starting Xcode

Having successfully installed the SDK and Xcode, the next step is to launch it so that we can write and then compile a sample Objective-C application. To start up Xcode, open the Finder, click theMacintosh HD device in the left had panel then double click on the Developer folder, followed by theApplications folder. Within this folder you should see an icon for Xcode. Double click on this icon to launch the tool. Once Xcode has loaded, and assuming this is the first time you have used Xcode on this system, you will be presented with theWelcome screen. On this screen, click on the option to Create your first Cocoa application to proceed to the developer documentation screen.

Starting a New Project

Each application created in Xcode is contained within a project. The first step in developing an application, therefore, is to create a new project. This is achieved by selecting theFile -> New Project... menu option. The New Project window provides a range of different types of Mac OS applications that can be created. If you downloaded and installed the iPhone version of the SDK, options are also provided to create a new iPhone application:


Creating a new Xcode project


To configure the project type, perform the following steps:

  • Under the Mac OS X section, scroll down the list and select Command Line Utility.
  • In the main panel, choose Foundation Tool then click on the Choose.. button.
  • In the resulting panel, enter sampleApp in the Save As: field.

By default, Xcode will put the project files in your Documents folder so be sure to create or specify a specific folder for your Objective-C development work before proceeding. Once you have defined a name and location for your project click theSave button to continue. Xcode will subsequently create the new project and open the main Xcode window:


The main Xcode window

Writing an Objective-C Application with Xcode

Xcode will create skeleton versions of the files needed to build a command-line based Objective-C application. Objective-C source files are identified by the.m filename extension. In the case of our example, Xcode has pre-created a main source file namedsampleApp.m and populated it with some basic code ready for us to edit. To view the code, selectsampleApp.m from the list of files so that the code appears in the editor area beneath the list. The skeleton code reads as follows:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // insert code here...
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}

Modify the NSLog line so that it reads:

    NSLog(@"This is my first Objective-C App!");

With the change made, the next step is to compile and run the application by selecting theBuild and Run option located in the Xcode Build menu. Once this option has been selected, Xcode will compile the sources and run the application within a terminal window:

Running a sample Objective-C application in Xcode

Compiling Objective-C from the Command Line

While Xcode provides a powerful environment that will prove invaluable for larger scale projects, for compiling a running such a simple application as the one we have been working with in this chapter it is a little bit of overkill. It is also a fact that some developers feel that development environments like Xcode just get in the way and prefer to use a basic editor and command line tools to develop applications. After all, in the days before integrated development environments came into favor, this was how all applications were developed. Whilst I'm not suggesting that everyone abandon Xcode in favor of thevi editor and GNU compiler, it is useful to know that the option to work from the command line is available.

Using your favorite text or programming editor, create a file named hello.m containing the following Objective-C code:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog (@"hello world");
        [pool drain];
        return 0;
}

Save the file and then open a Terminal window (if you aren't already working in one), change directory to the folder containing the source file and compile the application with the following command:

gcc -framework Foundation hello.m -o hello

Assuming the code compiles without error it can be run as follows:

./hello
2009-09-25 15:51:11.528 hello[3371:10b] hello world

Compared to using Xcode that seems much simpler, but keep in mind that the power of Xcode really becomes evident when you start developing larger scale projects.

Before moving on to learning the basics of the Objective-C programming language, we will cover the installation and use of Objective-C on non-Mac OS X systems.

OS 6.828工具安装 (Mac OS X) MIT OS 6.828 course tools installation on Mac OS XEnvironmentPreparationInstalling the cross compiler The official website of os 6.828 provide inadequate instructions to install JOS lab tools on OS X system. Here are records of my installation. Environment 阅读详情

相关推荐

mac配置opencv/c++(Xcode)

这两天想在自己mac电脑上配置C++与Opencv,在vscode、eclipse、xcode以及其他代码编辑工具中,最终选择了xcode(个人感觉运行比vscode好点,代码提示比eclipse好点)。 自己配置的过程如下: ps:xcode下载时间较长,可以事先在app商店下载xcode。 1.检查gcc -v 命令行窗口输入:gcc -v,查看mac自带gcc编译版本,是4.x(忘记了),要自己更新。 2.检查brew 若没有安装brew,首先安装brew,国内镜像源脚本: /bin/z

Sau_Hit的博客 3902

Homebrew安装 — A full installation of Xcode.app 8.3.2 is required to compile this software.

&nbsp;&nbsp;&nbsp;&nbsp;在使用Homebrew安装mongodb &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brew install mongodb &nbsp;&nbsp;&nbsp;&nbsp;报错:mongodb mongodb: A full installation of Xcode.app 8

idomyway的博客 4080

Mac OS X 搭建erlang开发环境

一、erlang源码包下载 到elang官网下载.tar.gz文件,下载地址为:http://www.erlang.org/download.html 这里使用的是17.4版本 二、得到otp_src_17.4.tar.gz源码包并解压安装 进入下载目录执行解压命令:tar -zxvf otp_src_17.4.tar.gz cd到解压之后的目录:cd otp_

chenside的博客 2437

mac 安装brew

快速安装 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed 会提示选择镜像。我选择的是1 中科大 后面各种进度,但是提示报错了 Error: homebrew-core is a shallow clone. homebrew-cask is a shallow clone. 按照提示的方法试试: git -C /usr/local/Homeb

bohu83的博客 5079

PERL开发环境搭建>>Windows,Linux,Mac OS

开发环境搭建特点perl解释器直接对源代码程序解释执行,是一个解释性的语言, 不需要编译器和链接器来运行代码>>速度快借鉴了C/C++, Basic, Pascal, awk, sed等多种语言, 定位于实用性语言,既具备了脚本语言的所有功能,也添加了高级语言功能没有"源代码保护条款"应用场合开发环境搭建。

weixin_40121264的博客 1642

46、Mac OS X 开发:Xcode 工具全解析

本文全面解析了Mac OS X开发中使用的Xcode工具,从开发者会员的选择、Xcode的安装步骤到Xcode的界面功能进行了详细介绍。同时,还涵盖了Xcode的偏好设置配置、文档使用技巧以及项目组织方式,为开发者提供了一站式的Xcode开发指南。无论是新手还是有经验的开发者,都能从中获取实用的信息,提升开发效率。

zero1的博客 122

Mac系统下Homebrew以及Telnet的安装与使用说明

小编的系统是MacOS Catalina10.15.4,由于新版本的macos 取消了内置的telnet命令,所以要使用telnet命令的话,需要大家手动安装。下面介绍一下如何安装: 首先安装Homebrew 通过brew命令来安装Telnet 一、安装 Homebrew 1、打开官网:https://brew.sh/,复制安装命令 安装命令如下: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ho.

小慌慌的博客 7615

避坑指南:Abaqus网格划分中90%用户会遇到的5个质量陷阱(附解决方案)

本文深入剖析Abaqus网格划分中90%用户会遇到的5个典型质量陷阱,包括单元扭曲、扫掠网格失败、尺寸梯度控制等,并提供工程级解决方案。通过Python脚本和虚拟拓扑等技巧,帮助用户提升网格质量,确保有限元分析结果的可靠性,适用于CAE工程师和仿真分析师。

weixin_29243279的博客 99

Install Android SDK, Eclipse, and Emulator (AVDs)

Android 开发环境在mac上的集成部署

2190

【顾邦小讲堂】第十九期 RC Snubber吸收电路详解:抑制MOSFET振铃现象与过冲的设计技巧!

通过RC Snubber电路有效抑制MOSFET DS端的过冲及振铃现象,帮助工程师们在设计中提升电路的稳定性和可靠性

GBupupup的博客 3789

Win11右键菜单显示更多选项设置默认展开方法

在Windows 11操作系统中,用户可能会发现右键点击桌面空白处时,弹出的菜单中仅显示“显示更多选项”,而并非直接展示所有可用的选项。这对于希望快速访问特定功能的用户来说,无疑增加了一些不便。为了优化这一体验,本文将介绍两种简单的方法,帮助用户设置Win11右键菜单,使其默认展开包含的所有选项。通过上述两种方法,用户可以轻松地将Win11右键菜单设置为默认展开所有选项,从而提高工作效率和便捷性。希望这篇文章对你有所帮助!

nntxthml的博客 1万+

黑马程序员—虚拟机的安装、Mac OS X系统使用、五个OC小程序

山东省烟台市莱山区烟台大学七号楼201

会飞の马 2288

离合器KP点自学习:从原理到工程实践的全景解析

本文全面解析了离合器KP点自学习的原理与工程实践,详细介绍了KP点的物理本质、控制价值及自学习方法。通过扭矩增量式和转速变化式学习法,结合不同变速箱构型的适配策略,提升离合器控制的精度与效率。文章还探讨了液压系统迟滞补偿和摩擦材料老化应对方案,为工程实践提供可靠保障。

weixin_33717117的博客 287

[转] 在 Mac OS X 下编译 Objective-C 运行时

原文地址:http://www.mulle-kybernetik.com/weblog/2011/10/how_to_build_libobjc_for_os_x.html Max OS X 版本:10.6.8 待编译运行时版本:437.3 刚刚自己试了一下,可以编译。 另:文章中提到头文件的包含路径为绝对路径,这样不好,可以改为相对路径, 比如:以 $(SRCROOT) 为参...

weixin_30586257的博客 73

《C++等级认证CCF-GESP真题解析》专栏总目录

❤️ 专栏名称:《C++等级认证CCF-GESP真题解析》🌸 专栏介绍:中国计算机学会GESP《CCF编程能力等级认证》C++编程(1~8级)历届真题解析。🚀 订阅专栏:订阅后可阅读专栏内所有真题解析,真题持续更新中,欢迎订阅!

人生就是一个不断学习的过程 6292

手把手入门YOLO到改进优化教程专栏介绍与说明——列表目录查阅(持续更新)

手把手入门YOLO到改进优化教程专栏介绍与说明——列表目录查阅(持续更新)

嵌入式阿齐Archie 2万+

IOS开发基本教程1 环境搭建中间有可能出现的问题

先说说 objective-c语言把 很多人都说他是c语言演变而来的   其中的语言跟c很相似 最明显的区别就是后缀名了一个是.c     而另一个是.h或者.m(.h一般成做源文件 或者声明为实现文件).m则是实现文件 单式 你也可以将他们写在一起。小的项目开发可以这么做。 objective-c 其实我认为从java转过去的比较容易理解 学习起来也相当容以  因为从

做个充实的人 583

比NTP还牛逼的时间同步协议:1588v2,亚微秒级!

1588v2,又称为Precision Time Protocol Version 2,即精密时间协议的第二版本,或称为PTPv2,是一种精密时间同步协议标准,旨在实现网络中设备之间的高精度时间同步。该协议由IEEE标准组织发布,并在网络测量和控制系统中得到广泛应用。1588v2的主要目的是在计算机网络中提供高度准确的时间同步。它可用于确保不同设备之间的时钟同步,从而协调它们的操作。这对于需要协同工作的系统、无线通信基站等具有关键性的应用非常重要。

网络技术联盟站 4281

如何在Mac OS X上安装gcc编译器

通常,您需要c或gcc编译器才能在Mac OS X中编译开源项目。问题是Mac OS X默认不安装gcc编译器。 如果您尝试安装或编译某些需要c / gcc编译器的项目,则会记录以下错误消息: configure: error: C compiler cannot create executables configure: error: no acceptable C compiler...

一名可爱的技术搬运工 9858

继电保护原理1.2-反时限过流保护

反时限过流保护

让你爱上电路设计 1万+

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Objective-C第一课 创建Xcode工程

介绍 Objective-C是苹果公司的iOS和Mac OS X操作系统上的原生编程语言。它是一门通用的编译型语言,能够用来构建命令行工具、图形界面应用以及二进制库。它同时提供了各种用来维护大规模框架的工具。 Objective-C应用程序类型 与C++类似的是,Objective-C也是设计用来给C语言添加面向对象的特性,只不过是它们采用了不同的思想来实现。Objective-

戴维营教育 1338

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

[入門級] 如何用 Mac OS X 的 Xcode 寫 C 語言程式

Acknowledgement: http://blog.yorkxin.org/2009/03/15/fundamental-c-with-xcode Deprecation Warning: 這篇是寫 Xcode 3.1.x 的故事。 4.x 的使用者介面變很多,這篇教學可能不適合。 這篇是給新手看的。 如果你在 Windows 習慣使用 Visual C++ 或 Dev-

Rauber_Hotzenplotz的专栏 8770

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

mac(苹果电脑系统)安装vs code编译运行c/c++

1

wshe 1万+
上一篇: Objective-C的历史
下一篇: 在Windows上使用GNUstep和Objective-C
NickTang
博客等级 码龄24年 261粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值