How can I enable Xcode refactor options for an ext

2019-05-09 23:56发布

I want to use XCode as an IDE for developing some AVR code. I did the following

1) create new project

2) select external build system

3) indicated i want it to be make, and told it NOT to "Pass build settings in environment"

4) copied my .c/.h/Makefile into the same directory i created the project in

5) added the .c/.h files to the project/target

6) verified that i can build (make) from both command line and Xcode

But I cannot use any of the refactor menu options, or jump to/reveal options. There appears to be no symbol information. Is there no way to use Xcode as more than just a simple C editor that uses an external build system????

If not, it's a bust for embedded development. Please tell me I'm wrong :(

2条回答
霸刀☆藐视天下
2楼-- · 2019-05-10 00:46

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.

查看更多
该账号已被封号
3楼-- · 2019-05-10 00:46

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.

查看更多
登录 后发表回答