使用 XCode 构建、分析、编辑 unix\linux 控制台程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8464381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using XCode for building, profiling, editing unix\linux console programs
提问by Marko Kevac
Can you, please, give some pointers for building, profiling and editing C/C++ unix/linux console programs in XCode.
请您为在 XCode 中构建、分析和编辑 C/C++ unix/linux 控制台程序提供一些指导。
I could not find any recent HOWTOs on the topic.
我找不到有关该主题的任何最新 HOWTO。
Seems that for XCode projects is a must. So I have created new project with "external build system" and added my *.c and *.h files via drag'n'drop.
似乎对于 XCode 项目来说是必须的。所以我用“外部构建系统”创建了新项目,并通过拖放添加了我的 *.c 和 *.h 文件。
But I could not "attach to process" from there, because menu item is grayed.
但我无法从那里“附加到处理”,因为菜单项是灰色的。
Also, code completing and code jumping does not work, even though definition of structure is in the same file.
此外,即使结构定义在同一个文件中,代码完成和代码跳转也不起作用。
The question is about building/profiling/editing existing C/C++ programs, not creating new ones.
问题是关于构建/分析/编辑现有 C/C++ 程序,而不是创建新程序。
For example this person is using XCode for MySQL development: http://dom.as/2011/09/25/blowing-up-in-memory/
例如,此人正在使用 XCode 进行 MySQL 开发:http: //dom.as/2011/09/25/blowing-up-in-memory/
回答by David M. Syzdek
For the code completing, code jumping, etc, you need to create a build target for the utility. I've been using Xcode for years to develop CLI utilities which I then port to other *nix platforms.
对于代码完成、代码跳转等,您需要为该实用程序创建一个构建目标。我多年来一直使用 Xcode 来开发 CLI 实用程序,然后将其移植到其他 *nix 平台。
Here are the basic instructions for creating a build target which will allow you to make full use of the Xcode environment when working on your utility:
以下是创建构建目标的基本说明,可让您在处理实用程序时充分利用 Xcode 环境:
- Create an empty project.
- Add a target using the "Command Line Tool" template (Menubar -> File -> New -> New Target).
- Delete the files added by the template (usually will be the name of the target).
- Add the source code to your Xcode project.
- Open the build phases for the target you created:
- Click on the project name in the navigator.
- Select your target from the center panel.
- Click on the "Build Phases" tab.
- Under "Compile Sources" added the sources required to build your utility.
- Under "Link Binary With Libraries" add the required libraries to link your utility.
- 创建一个空项目。
- 使用“命令行工具”模板(菜单栏 -> 文件 -> 新建 -> 新目标)添加目标。
- 删除模板添加的文件(通常是目标的名称)。
- 将源代码添加到您的 Xcode 项目中。
- 打开您创建的目标的构建阶段:
- 在导航器中单击项目名称。
- 从中心面板中选择您的目标。
- 单击“构建阶段”选项卡。
- 在“编译源”下添加了构建实用程序所需的源。
- 在“Link Binary With Libraries”下添加所需的库以链接您的实用程序。
You may need to add a scheme for your new target, if so:
如果是这样,您可能需要为新目标添加方案:
- Open the scheme manager (Menubar -> Product -> Manage Schemes).
- Click on the "Autocreate Schemes Now" button.
- 打开方案管理器(菜单栏 -> 产品 -> 管理方案)。
- 单击“立即自动创建方案”按钮。
You should now be able to use the same tools to build/profile/edit your utility as you would for an OS X or iOS application.
您现在应该能够使用与 OS X 或 iOS 应用程序相同的工具来构建/配置/编辑您的实用程序。
Here are a few examples where I have done the above:
以下是我已完成上述操作的几个示例:
- https://github.com/bindle/iOSPorts(has Xcode projects for OpenSSL, OpenLDAP, Cyrus SASL, and PCRE, granted they are currently compiling for iOS).
- https://github.com/bindle/odbcshell(project I wrote for Linux/FreeBSD systems using Xcode).
- https://github.com/bindle/iOSPorts(有用于 OpenSSL、OpenLDAP、Cyrus SASL 和 PCRE 的 Xcode 项目,当然他们目前正在为 iOS 编译)。
- https://github.com/bindle/odbcshell(我使用 Xcode 为 Linux/FreeBSD 系统编写的项目)。
回答by Basile Starynkevitch
Xcodeis an Apple thing and you don't have it on Linux (and I'm not sure that using it in a cross-compiler setting -host being an Apple, target being a Linux- is a good way to work, and it probably is not possible).
Xcode是 Apple 的东西,而你在 Linux 上没有它(我不确定在交叉编译器设置中使用它 - 主机是 Apple,目标是 Linux - 是一种很好的工作方式,而且它可能是不可能的)。
On Linux, you could use traditionnal tools (like a mix of Emacs, Make, GCC, ... which is the way Unix people work), or you could try some fancy IDElike anjuta, netbeans, eclipseand many many others.
在 Linux 上,你可以使用传统的工具(比如 Emacs、Make、GCC 的混合……这是 Unix 人的工作方式),或者你可以尝试一些花哨的IDE,比如anjuta、netbeans、eclipse和许多其他工具。
I am old enough to find IDE nearly useless for me, and I am very happy using my mixture of Emacs, Make, GCC, Svn or Git, Gdb, etc. I know many experimented Linux developers not using IDEs.
我年纪大了,发现 IDE 对我来说几乎没用,我很高兴使用我的 Emacs、Make、GCC、Svn 或 Git、Gdb 等组合。我知道许多试验过的 Linux 开发人员不使用 IDE。
回答by Mr. Berna
I used Xcode to write many C and C++ console programs when I was in school. I started each with the Xcode console app template. I depended upon standard C libraries and POSIX. I stayed away from Apple specific libraries. I could build, run, profile, and debug the programs from within Xcode. The only thing I couldn't do within Xcode was produce a portable build configuration. For these class project console programs I would just hand write a makefile for each project. Since I knew from the start that I'd need a hand written makefile, I kept the build process simple.
我在学校时使用 Xcode 编写了许多 C 和 C++ 控制台程序。我从 Xcode 控制台应用程序模板开始。我依赖于标准 C 库和 POSIX。我远离 Apple 特定的库。我可以在 Xcode 中构建、运行、分析和调试程序。我在 Xcode 中唯一不能做的就是生成可移植的构建配置。对于这些类项目控制台程序,我只需为每个项目手写一个 makefile。因为我从一开始就知道我需要一个手写的 makefile,所以我让构建过程保持简单。
Now I write mostly iOS apps, but I occasionally write a console app to preprocess data for my iOS apps. I don't see any improvement in newer versions of Xcode for building cross platform build systems. Xcode is focused on iOS and Mac apps, but concedes the need for console programs and includes some Mac OS X specific support.
现在我主要编写 iOS 应用程序,但偶尔也会编写一个控制台应用程序来为我的 iOS 应用程序预处理数据。我没有看到用于构建跨平台构建系统的 Xcode 的新版本有任何改进。Xcode 专注于 iOS 和 Mac 应用程序,但承认需要控制台程序并包含一些 Mac OS X 特定支持。
So my advice for writing console programs for other platforms in Xcode is to keep the build process simple. Start with the Xcode console app project template. Stay with the Xcode project build systems. Make the program work using the Xcode IDE features. Then port the build process to the external build system. Write a makefile, or use whatever build tools you prefer. Use the command line on Mac OS X to build and test the program on Mac OS X from this new build system. Then move the project to another platform and build and test again. I rarely found any problems when I got as far as the second platform.
所以我在 Xcode 中为其他平台编写控制台程序的建议是保持构建过程简单。从 Xcode 控制台应用程序项目模板开始。继续使用 Xcode 项目构建系统。使用 Xcode IDE 功能使程序运行。然后将构建过程移植到外部构建系统。编写一个 makefile,或使用您喜欢的任何构建工具。在 Mac OS X 上使用命令行从这个新的构建系统在 Mac OS X 上构建和测试程序。然后将项目移动到另一个平台并再次构建和测试。当我到达第二个平台时,我很少发现任何问题。
I even used this method working on teams where my team members were not on Macs. We each used our own choice in build systems, sharing the source code files. Yet, I could see maintaining multiple build systems for large complex programs would quickly become untenable. At which point I would recommend standardizing on one IDE.
我什至在我的团队成员不在 Mac 上的团队中使用这种方法。我们每个人都在构建系统中使用自己的选择,共享源代码文件。然而,我可以看到为大型复杂程序维护多个构建系统将很快变得站不住脚。在这一点上,我建议在一个 IDE 上进行标准化。