为什么在 typedef 存在时出现未解析的外部符号错误

Why am I getting an Unresolved External Symbol error while the typedef is present?

本文关键字:外部 错误 符号 typedef 存在 为什么      更新时间:2023-10-16

我正在创建一个四元数到欧拉角的转换器,我写了这段代码:

//(...)
/*
* 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 文件中的声明中。