1>OpenGLTest.obj : error LNK2019: unresolved external symbol "void __cdecl build_rotmatrix(float (* const)[4],float * const)" (?build_rotmatrix@@YAXQAY03MQAM@Z) referenced in function "void __cdecl recalcModelView(void)" (?recalcModelView@@YAXXZ)
1>OpenGLTest.obj : error LNK2019: unresolved external symbol "void __cdecl add_quats(float *,float *,float *)" (?add_quats@@YAXPAM00@Z) referenced in function "void __cdecl animate(void)" (?animate@@YAXXZ)
1>OpenGLTest.obj : error LNK2019: unresolved external symbol "void __cdecl trackball(float * const,float,float,float,float)" (?trackball@@YAXQAMMMMM@Z) referenced in function "void __cdecl motion(int,int)" (?motion@@YAXHH@Z)
1>D:\code\OpenGLTest\Debug\OpenGLTest.exe : fatal error LNK1120: 3 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.47
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
在vs2010中调试程序时,出现以上错误。
查了很多资料,说是没有添加相应的lib到工程属性配置中。可是我已经添加过了,出现的这样错误。
经过查找资料,发现一篇很有用的文章,提示说是由于在C++中使用用C编写的文件导致的错误。
请参考:
http://www.cppblog.com/Dutyboy/archive/2010/11/19/134082.html
The problem with your project is that you are using a "C" style exported library in your C++ projects. When the compiler generates mangled names for C++ functions, they are different from unmangled names generated by the C compiler and hence the C++ compiler will not be able to link with the methods imported from coredll.lib.
The solution to this problem is - while including the header windbase_edb.h, you can explicitly tell the compiler that all functions included from this header are "C" style functions by changing your inclusion as below.
extern "C"
{
#include
}
或者
#ifndef _C_H_
#define _C_H_
#ifdef __cplusplus //__cplusplus是双下划线
extern "C" {
#endif
extern int add(int, int);
#ifdef __cplusplus
}
#endif
#endif /* _C_H_ */
开始搜到这篇文章,看到是英文,所以还以为是大众的答案呢,到后面仔细一看,才知道不一样。
say to me:以后看到英文的文章,不能抵触哦,要好好看。。