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

标签 c++ c visual-c++ visual-studio-2012

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

//(...)
/*
* 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)    .\calculatorSAMP\calculatorSAMP.obj calculatorSAMP
Error   2   error LNK1120: 1 unresolved externals   .\calculatorSAMP\Release\calculatorSAMP.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++ - 为什么在存在 typedef 时出现未解析的外部符号错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13546598/

相关文章:

c++ - 如何实现与 C++ 的 MinGW 的 visual studio 相同的名称修改?

c++ - 读取大量ASCII码并以二进制形式写入

c++ - C++和Lua之间的简单数学计算不同

android - 使用 Gstreamer 播放 PCM 文件

c - 如果x!= x给出相同的结果,为什么isnan(x)存在?

c++ - 是否真的可以使用 CFile 和 CStdio 类将数据附加到 MFC 中的文本文件?

c++ - Visual Studio 静态链接(freeglut,glew)

c++ - 怎么了?悬挂指针?

c - SO_REUSEADDR 似乎保持值 4

c++ - 库正常编译时出现链接器错误 (LNK2001)