简体   繁体   English

C /客观问题

[英]c/objective-c question

I am truing to use ac function in a .c file from within my objective-c class. 我正在努力在我的Objective-C类中的.c文件中使用ac函数。 I have imported the header for the c file. 我已经导入了c文件的标头。 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 “ gluUnProject(float,float,float,float const *,float const *,int const *,float *,float *,float *)”,引用自:-[GLView checkCollission:object:]在GLView.o中ld:符号(s)找不到collect2:ld返回1退出状态

Any idea how I can resolve this issue ? 知道如何解决这个问题吗? Any help is certainly appreciated. 任何帮助当然是感激的。 Qutaibah Qutaibah

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. 通常,这是由于将代码编译为C并从C ++或其他方式包含在内而引起的。

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: 通常,您可以通过在头文件中添加以下内容来确保头文件中的函数定义强制任何C ++编译器使用C语法来解决此问题:

#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++. 此方法还确保.c文件本身将函数定义视为C,而不是偶然将其编译为C ++。

If you do not wish to alter the header, you can encapsulate the #include statement in the same way. 如果您不想更改标题,则可以用相同的方式封装#include语句。 This will however not ensure correct compilation of the .c file itself. 但是,这将无法确保正确编译.c文件本身。

EDIT: Just a thought: I presume that you are actually compiling the .c file? 编辑:只是一个想法:我想您实际上是在编译.c文件吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM