简体   繁体   English

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

[英]Import existing c++ project into Xcode IDE

I am trying to open an existing C++ open-source library in XCode to publish it with my own modification/additions. 我试图在XCode中打开一个现有的C ++开源库,用我自己的修改/添加来发布它。 The library is Tesseract-OCR , which does not include a .xcodeprojet file. 该库是Tesseract-OCR ,它不包含.xcodeprojet文件。

Since XCode can function as an IDE, is it possible to open a bunch of files as a single project in XCode? 由于XCode可以作为IDE运行,是否可以在XCode中将一堆文件作为单个项目打开? Is there an easy way to produce an XCode project? 有没有简单的方法来生成XCode项目?

There are several ways you could do it, depending on the level of IDE integration you want. 您可以通过多种方式执行此操作,具体取决于所需的IDE集成级别。 There's no direct way of importing a Makefile-based project into Xcode. 没有直接的方法将基于Makefile的项目导入Xcode。 You can create a project that builds via 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. 您可以创建一个通过Makefile 构建的项目,但是您不会获得使用IDE的许多好处,因为诸如单词完成之类的编辑器功能依赖于Xcode能够解析项目中的文件。 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. 为此,请创建一个新项目并添加一个自定义目标,其中包含一个脚本构建阶段,该阶段只调用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. 我已经广泛使用这种方法来构建boost库。 If this is a configure && make type project then you will probably have to run the configure step first, and ensure any top level config.h files are included in the project. 如果这是一个configure && make type项目,那么您可能必须首先运行configure步骤,并确保项目中包含任何顶级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项目很可能是一个涉及的任务

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?" 我意识到你明确要求Xcode,但是如果你真的试图解决“我有现有的C ++代码从命令行构建和运行良好的问题,我想在IDE中编写和调试它,我该怎么办?” my firm recommendation would be to avoid Xcode and go for Eclipse. 我的建议是避免使用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. 原因是,据我所知,Xcode无法摄取命令行构建环境,并且有效地要求您从头开始在Xcode中重新创建make进程。 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. 而在Eclipse中,一切都是围绕Makefile构建的。 So in my case I got to the "step through code with working code completion" in Eclipse a lot quicker vs. never in Xcode. 所以在我的情况下,我在Eclipse中的“通过代码完成工作代码完成”的速度要快得多,而不是在Xcode中。 This of course could be because I'm an Xcode noob, but my 2c. 这当然可能是因为我是Xcode noob,但是我的2c。

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. 您可以在XCode中构建基于c ++的库。 People do that every day. 人们每天都这样做。 You can even use one of the Xcode templates to get you started. 您甚至可以使用其中一个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. 剩下的问题将是确保源代码的依赖关系已经内置到Mac的SDK中。 (Don't hold your breath for linking to MFC) (请勿屏住呼吸以连接到MFC)

It's a general question... So it's a general answer. 这是一个普遍的问题......所以这是一个普遍的答案。

To create an Xcode project from an existing cmake project, you can run cmake -G Xcode . 要从现有的cmake项目创建Xcode项目,您可以运行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: 例如:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM