简体   繁体   中英

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. The library is Tesseract-OCR , which does not include a .xcodeprojet file.

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?

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 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. 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.

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 && 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.

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

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.

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 is a useable IDE for library creation.

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.

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

Another good reference is 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.

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

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)

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 . 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”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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