tags:

views:

47

answers:

1

I am truing to use a c function in a .c file from within my objective-c class. I have imported the header for the c file. but I am still getting a problem and my program would not compile.

Undefined symbols:

"gluUnProject(float, float, float, float const*, float const*, int const*, float*, float*, float*)", referenced from: -[GLView checkCollission:object:] in GLView.o ld: symbol(s) not found collect2: ld returned 1 exit status

Any idea how I can resolve this issue ? Any help is certainly appreciated. Qutaibah

+3  A: 

This error is posted by the linker and not the compiler. Often this is caused by the code being compiled as C and included from C++ or the other way around.

You can normally fix this by ensuring that the function definitions in the header file enforces any C++ compiler to use C syntax by adding the following to the header:

#ifdef __cplusplus
extern "C" {
#endif

... definitions goes here ...

#ifdef __cplusplus
}
#endif

This method also ensures that the .c file itself is treating the function definitions as C and not by accident get compiled as C++.

If you do not wish to alter the header, you can encapsulate the #include statement in the same way. This will however not ensure correct compilation of the .c file itself.

EDIT: Just a thought: I presume that you are actually compiling the .c file?

Claus Broch
Thanks Claus, In xCode, I right click on 'glu.c' and hit compile. in the header for the glu.c file: #ifndef _GLU_H_#define _GLU_H_#endif
Have you actually added the glu.c file to your project, so it is part of the build?
Claus Broch