How can I enable Xcode refactor options for an external build project?

人走茶凉 提交于 2019-12-05 23:33:16

I found a workaround/solution. Create a second target called "Dummy" or something like that, that is based on the Command Line Tool template of type C. Select all the .c files and in the "Targets" pane on the left side bar, check the new Dummy project (or if the options change, as they seem to often, do whatever gestures necessary to make Dummy depend on your C files).

It will create a Dummy directory and a couple of other Dummy files which you can remove if you want. You never bother building 'Dummy', in fact, if it's an embedded project with separate toolchain, likelihood is nearly 100% that it won't compile as a Command Line Tool for OSX anyway. :)

Apparently XCode needs this indirect hint to know that your .c files are indeed real C files and can be parsed/introspected as such.

As you add new .c files which your external build system likely see automatically, make sure you include them as a dependent for the Dummy target.

I was able to get this to work using XCode 6.1. In my case I'm using C++ but it should also work with C as some of my C++ files make C function calls. Here's what I did:

  1. Create a dummy target using: File->New->Target
  2. For the template choose: OS X->Application->Command Line Tool
  3. Click Next
  4. Fill out the Product Name, etc.
  5. Select C++ for the Language field.
  6. Click Finish.

Back in the Project Navigator pane:

  1. Right click on the new 'dummy' target
  2. Select: Add files to 'your project name'
  3. Browse to select your directories/files to add.

Once the files were added to the Dummy target, I could then open a file under my normal target, right click on a method and Refactor, Jump To Definition, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!