C++ error LNK2019: "unresolved external symbol"解决方法

1>  LINK : D:\code\OpenGLTest\Debug\OpenGLTest.exe not found or not built by the last incremental link; performing full link
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:以后看到英文的文章,不能抵触哦,要好好看。。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值