将现有的 C++ 项目导入 Xcode IDE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5034286/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:14:14  来源:igfitidea点击:

Import existing C++ project into Xcode IDE

c++xcodeimport

提问by Jes Chergui

I am trying to open an existing C++ open-source library in Xcode to publish it with my own modification/additions. The library is Tesseract-OCR, which does not include a .xcodeprojfile.

我正在尝试在 Xcode 中打开一个现有的 C++ 开源库,以通过我自己的修改/添加来发布它。库是Tesseract-OCR,其中不包含.xcodeproj文件。

Since Xcode can function as an IDE, is it possible to open a bunch of files as a single project in Xcode? Is there an easy way to produce an Xcode project?

既然 Xcode 可以作为 IDE 运行,那么是否可以在 Xcode 中将一堆文件作为一个项目打开?有没有一种简单的方法来生成 Xcode 项目?

回答by the_mandrill

There are several ways you could do it, depending on the level of IDE integration you want. There's no direct way of importing a Makefile-based project into Xcode. You can create a project that buildsvia the Makefile, but you wouldn't get many of the benefits of using an IDE, since the editor features such as word completion rely on Xcode being able to parse the files in the project. You will be able to use the debugger though. To do this, create a new project and add a custom target with a script build phase that just calls down to Makefile.

有多种方法可以做到这一点,具体取决于您想要的 IDE 集成级别。没有将基于 Makefile 的项目导入 Xcode 的直接方法。您可以创建一个通过 Makefile构建的项目,但您不会获得使用 IDE 的许多好处,因为诸如单词补全等编辑器功能依赖于 Xcode 能够解析项目中的文件。不过,您将能够使用调试器。为此,请创建一个新项目并添加一个自定义目标,该目标具有仅调用 Makefile 的脚本构建阶段。

If however the project you're building compiles very easily, ie without requiring a lot of macros to be set up, include paths, etc, then it may be simple to just create an empty project and merely add all source files to it. I've used this method extensively for building boost libraries. If this is a configure && maketype project then you will probably have to run the configure step first, and ensure any top level config.hfiles are included in the project.

然而,如果您正在构建的项目很容易编译,即不需要设置大量宏、包含路径等,那么创建一个空项目并将所有源文件添加到其中可能很简单。我已经广泛使用这种方法来构建 boost 库。如果这是一个configure && make类型项目,那么您可能必须首先运行配置步骤,并确保config.h项目中包含任何顶级文件。

If the project has a complex makefile then it is likely to be an involved task to create a useful Xcode project

如果项目有一个复杂的 makefile,那么创建一个有用的 Xcode 项目很可能是一项复杂的任务

回答by Stephan

I realise you asked explicitly for Xcode, but in case you were actually trying to solve the problem of "I have existing C++ code which builds and runs fine from the command line, and I'd like to code and debug it in an IDE, what should I do?" my firm recommendation would be to avoid Xcode and go for Eclipse.

我意识到您明确要求使用 Xcode,但如果您实际上是在尝试解决“我现有的 C++ 代码可以从命令行构建和运行良好的问题,我想在 IDE 中对其进行编码和调试,我该怎么办?” 我坚定的建议是避免使用 Xcode 并使用 Eclipse。

The reason is that as far as I can tell, Xcode has no way of ingesting the command line build environment and effectively requires you to recreate the make process inside Xcode from scratch. Fine for tiny projects, but anything with more than a few source files and it quickly becomes painful. Whereas in Eclipse everything is built around Makefiles. So in my case I got to the "step through code with working code completion" in Eclipse a lot quicker vs. never in Xcode. This of course could be because I'm an Xcode noob, but my 2c.

原因是,据我所知,Xcode 无法摄取命令行构建环境,并且有效地要求您从头开始在 Xcode 内重新创建 make 过程。对于小型项目来说很好,但是对于包含多个源文件的任何项目,它很快就会变得痛苦。而在 Eclipse 中,一切都是围绕 Makefile 构建的。所以在我的例子中,我在 Eclipse 中“逐步完成代码并完成工作代码”比在 Xcode 中要快得多。这当然可能是因为我是 Xcode 菜鸟,但我的 2c.

回答by Elgar de Groot

To create an Xcode project from an existing cmake project, you can run cmake -G Xcode. It produces some folders and files apart from the project file, so it might be better to create a folder for it first. For example:

要从现有的 cmake 项目创建 Xcode 项目,您可以运行cmake -G Xcode. 除了项目文件之外,它还会生成一些文件夹和文件,因此最好先为其创建一个文件夹。例如:

mkdir -p build/xcode
cd build/xcode
cmake -G Xcode ../..

回答by Dru Freeman

Xcode is a useable IDE for library creation.

Xcode 是一个可用于库创建的 IDE。

Of course a good first step is to see if the one source code will build on its own with configure scripts that are included.

当然,良好的第一步是查看源代码是否会使用包含的配置脚本自行构建。

If not, it becomes a question of how many libraries you need to link in.

如果没有,就变成了需要链接多少个库的问题。

There are resources online (or at least there used to be) for using Xcode (or perhaps it's forerunner Product builder) for porting Unix projects to Mac.

有在线资源(或至少曾经有)使用 Xcode(或者它可能是前身产品构建器)将 Unix 项目移植到 Mac。

Good tutorial at: http://www.macresearch.org/tutorial-introducing-xcode-30-organizer

很好的教程:http: //www.macresearch.org/tutorial-introducing-xcode-30-organizer

Another good reference is Darwin Ports.

另一个很好的参考是 Darwin Ports。

As for doing this on your own. You can build c++ based libraries in XCode. People do that every day. You can even use one of the Xcode templates to get you started.

至于自己做这件事。您可以在 XCode 中构建基于 C++ 的库。人们每天都这样做。您甚至可以使用其中一个 Xcode 模板来开始。

However, library dev requires more experience with Xcode then say a simple Cocoa "Hello World" app.

然而,库开发需要更多的 Xcode 经验,然后说一个简单的 Cocoa “Hello World”应用程序。

The remaining questions will be assuring that the source code's dependencies are already built into the Mac's SDK. (Don't hold your breath for linking to MFC)

剩下的问题是确保源代码的依赖项已经内置到 Mac 的 SDK 中。(链接到MFC不要屏住呼吸)

It's a general question... So it's a general answer.

这是一个笼统的问题...所以这是一个笼统的答案。

回答by user7803475

In Xcode8,there is "Xcode->file->add files to...",then choose your files.If you want to add several files at a time,press "Cmd" when you are choosing.

在Xcode8中,有“Xcode->file->add files to...”,然后选择你的文件。如果你想一次添加多个文件,选择时按“Cmd”。