Xcode #import cannot find .h file

I am trying to import a .h file from an old xcode project into my current one. The file location is the same as other files in the project (I moved it there), but after using #import in my main program file, when I try to run the program, I get the following failure:

"_ OBJC_CLASS _ $ _ Faction" referenced by:

objc-class-ref-to-fraction at 9.1main.o

ld: character not found collect2: ld returned 1 exit status

Does anyone know how to fix this? Thanks!

+4
source share
3 answers

Assuming you added Fraction.m to the project,

In the Group and Files view, select Fraction.m

Show editor view (Menu → View → Zoom Editor)

Select the "Details" tab. There you should (again) see the Fraction.m file.

In the far right corner of the column is a tiny symbol of the target. Make sure the column has a checkmark.

This ensures that your Fraction class is enabled when Xcode creates the application.

+3
source

The same thing happened, which I did:

1.- Press the @ Show Project Navigator tab.

2.- Select your program folder, the same as your main file, i.e. "Program 1"

3.- On the same tab, go to the bottom left of the screen, there are 4 characters and a search box. Click on the icon on the left, the one that has a + sign (add a new file).

4.- In the minimize window, select: "Add files to the program ...".

5.- A new search window appears, find the files you want to add (for example, .h and .m). Click the Add button ...

Voila!

Please note that the files you add MUST be in the same folder as your main file, otherwise you will have problems compiling.

Hope this helps.

+3
source

Go to Xcode Project Settings → Phase Build → In the headers section, find your .h file and move it to the open list.

0
source

All Articles