gpt4 book ai didi

c++ - 从 .cpp 文件创建 Xcode 项目

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:24:49 30 4
gpt4 key购买 nike

我有许多 C++ 项目/文件,我想将其创建到 命令行工具 文件类型 .xcodeproj 中以用于调试目的。我能想到的成功执行此操作的唯一方法是创建一个新的 Command Line Tool Xcode project > Type: C++ 然后添加 C++ 项目目录或文件。有没有办法在不创建新项目并手动向其中添加文件的情​​况下执行此操作?

注意:Xcode 默认打开单独的 .cpp 文件,但它们没有关联为 Command Line Tool 或具有 .xcodeproj 文件类型。

最佳答案

寻找做同样的事情我找到了这个链接,希望对您有用

http://hiltmon.com/blog/2013/07/05/xcode-and-the-simple-c-plus-plus-project-structure/

该链接向您展示了如何配置 Xcode 以在 C++ 项目中工作,有点棘手但有效。

Xcode and the Simple C++ Project Structure

In a previous post, I talked about a A Simple C++ Project Structure that I am using to create a bunch of high-speed daemons for work.

It’s been fun using TextMate 2 and a Terminal to make and run the project, but now that I am getting to the meat of the coding, I’d prefer to use an IDE to help me navigate and debug the code.

Here’s how to set up Xcode 4 on the Mac to compile using our Makefile and run/debug the application.

Note that since these projects already exist, there is a minor shenanigan involved in setup.

Step 1: Create an External Build System Project

Start Xcode and choose File / New Project.

Click on Other then choose External Build System.

Click Next.

Input your project name, I use the existing project’s name so that the Xcode project file matches.

Then click Next.

Now you will save this project at the root of the Simple C++ project folder. Just select the project root and hit Create.

Step 2: Move the Project File

The problem is this. If you has chosen the root of your Projects folder where the Simple C++ project resides, Xcode would have replace the simple project folder with a blank folder and its *.xcodeproj file. That’s not what we want.

So instead, we chose the root of the project itself.

But Xcode has created a subfolder named after your project and placed the *.xcodeproj file in that. That’s not what we want either. So lets fix it up.

Quit XCode.

Drag the *.xcodeproj from the subfolder and drop it on the project root. Now delete the subfolder.

Double-click the moved *.xcodeproj to open the project again in Xcode.

Step 3: Add the sources

At the bottom left of the Xcode window, click the + icon. Then choose Add files to “Your Project Name”.

Select everything except the build folder and choose Add.

Step 4: Test the Build

Click on the project at the top to see the Project and Targets panel. You should see an External Build Tool Configuration already setup to use the Makefile we had before.

To build, press ⌘B.

Step 5: Run It

We still need to do one more thing and that is to tell Xcode which executable to run.

Under the Product menu, choose Scheme then Edit Scheme.. or press ⌘<.

Click on Run in the left pane. The click on the drop-down next to Executable and choose Other…. Find the executable in the bin folder and click on it.

If you prefer, you can change the debugger to GDB as well.

To pass arguments to the default run, click the arguments tab and add them there.

Click OK to save.

Press ⌘R to run, and Xcode will bring up a console window to display the program’s output.

关于c++ - 从 .cpp 文件创建 Xcode 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941209/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com