为什么在 typedef 存在时出现未解析的外部符号错误
Why am I getting an Unresolved External Symbol error while the typedef is present?
我正在创建一个四元数到欧拉角的转换器,我写了这段代码:
//(...)
/*
* Converter Includes
*/
#include "EulerAngles.h"
//(...)
static cell AMX_NATIVE_CALL n_QuatToEuler( AMX* amx, cell* params )
{
Quat q;
q.x = amx_ctof(params[1]);
q.y = amx_ctof(params[2]);
q.z = amx_ctof(params[3]);
q.w = amx_ctof(params[4]);
EulerAngles EU = Eul_FromQuat(q,params[5]);
//(...)
return 1;
}
//(...)
我将 http://tog.acm.org/resources/GraphicsGems/gemsiv/euler_angle/的EulerAngles.c包含在我的项目中,还将所有其他文件下载到我的项目中。
当我尝试编译我的项目时,我从Visual Studio 2012收到以下错误消息:
Error 1 error LNK2001: unresolved external symbol "struct Quat __cdecl Eul_FromQuat(struct Quat,int)" (?Eul_FromQuat@@YA?AUQuat@@U1@H@Z) .calculatorSAMPcalculatorSAMP.obj calculatorSAMP
Error 2 error LNK1120: 1 unresolved externals .calculatorSAMPReleasecalculatorSAMP.dll calculatorSAMP
包含在EulerAngles.h中的QuadTypes.h具有以下代码:
/**** QuatTypes.h - Basic type declarations ****/
#ifndef _H_QuatTypes
#define _H_QuatTypes
/*** Definitions ***/
typedef struct {float x, y, z, w;} Quat; /* Quaternion */
enum QuatPart {X, Y, Z, W};
typedef float HMatrix[4][4]; /* Right-handed, for column vectors */
typedef Quat EulerAngles; /* (x,y,z)=ang 1,2,3, w=order code */
#endif
我在这里错过了什么?
我试图将其编辑为:
/**** QuatTypes.h - Basic type declarations ****/
#ifndef _H_QuatTypes
#define _H_QuatTypes
/*** Definitions ***/
struct Quat {float x, y, z, w;}; /* Quaternion */
enum QuatPart {X, Y, Z, W};
typedef float HMatrix[4][4]; /* Right-handed, for column vectors */
#define EulerAngles Quat ; /* (x,y,z)=ang 1,2,3, w=order code */
#endif
但它导致了更多的错误。
错误表明您缺少一个函数:
Eul_FromQuat(struct Quat,int);
我在您提供的代码中没有看到该函数。
所以你的编译器和我都得出结论,它丢失了,是一个未解决的符号。
如果是 .c 文件,则默认编译为 C。
您必须更改该文件的"编译为"选项,或者将extern "C"
添加到 .h 文件中的声明中。
相关文章:
- Visual Studio 2017 中的 QtMetaObject 未解决的外部错误
- 无法确定未解决的外部错误来自何处
- DLIB On visual studio 2015抛出一个未解决的外部错误
- 排除外部错误R6025-纯虚拟函数调用
- 如何在我的指针和阵列功能中修复未解决的外部错误-LNK2019和LNK1120
- 将外部错误代码映射到std :: error_condition
- 虚拟函数未解决的外部错误
- 非常简单的 x64 组装/C++应用程序中未解决的外部错误
- 链接到SFML的未解决的外部错误(SFML 2.2,Visual Studio Community 2013)
- 为什么我的代码会出现LNK2019未解决的外部错误
- 尝试重载=运算符时出现1个未解析的外部错误
- c++中链表代码中未解决的外部错误
- 操作员过载未解决的外部错误LNK1120、LNK2019
- 未解决的外部错误
- 模板上的算术运算符过载,导致无法解析的外部错误
- 致命错误LNK1120:1 个未解析的外部 & 错误 LNK2019:函数___tmainCRTStartup中引用_main未解析的外部符号
- 模板c++中未解决的外部错误
- C++程序使用 C 库标头将"this"识别为关键字。外部"C"错误?
- DLL LNK2019错误(未解析的外部错误__imp)
- 如何将DLL链接到我的主项目?(正在获取未解析的外部错误)