C++中的链接错误
Linking error in C++
我只是在对我一直在做的一个在OpenGL中渲染场景的项目进行最后的润色 - 我基于我为相机类编写的一些旧代码(因为我不想重新计算数学!),但是我之前将相机类作为main的一部分.cpp 我想将其移动到它自己的单独 .h/.cpp 文件中,以便可重用性/清晰度/一般良好实践。
我还用我编写的 Mouse 类替换了一个基本的结构体来保持鼠标的 x 和 y 位置。
我在 Windows 消息处理程序中更改了一些代码,以便在释放鼠标左键时更新相机 - 但是我收到一个奇怪的链接错误 -
1>main.obj : 错误 LNK2001: 未解决 外部符号"公共:无效 __thiscall 相机::移动相机(int,int,int,int)" (?moveCamera@Camera@@QAEXHHHH@Z)
Windows 消息处理程序中的代码是 -
case WM_LBUTTONUP:
Mouse.SetPos(lParam);
x_mouse_end = Mouse.GetXPos();
y_mouse_end = Mouse.GetYPos();
Camera.moveCamera(x_mouse_start, y_mouse_start, x_mouse_end, y_mouse_end);
SetCamera();
break;
我传递给 Camera.moveCamera() 的参数应该是整数。
moveCamera() 函数如下 -
//Moves the camera based on a user dragging the mouse
inline void Camera::moveCamera(int old_x, int old_y, int new_x, int new_y)
{
//To store the differences between the old and new mouse positions
int x_difference, y_difference;
//If the mouse was dragged to the right, move the camera right
if(new_x > old_x)
{
x_difference = new_x - old_x;
x_difference = x_difference / 25;
if(yaw > 350)
{
yaw = 0;
}
else
{
yaw = yaw + x_difference;
}
}
//If the mouse was dragged to the left, move the camera left
if(new_x < old_x)
{
x_difference = old_x - new_x;
x_difference = x_difference / 25;
if(yaw < 10)
{
yaw = 360;
}
else
{
yaw = yaw - x_difference;
}
}
//If the mouse was dragged down, move the camera down
if(new_y < old_y)
{
y_difference = new_y - old_y;
y_difference = y_difference / 20;
if(pitch < 10)
{
pitch = 360;
}
else
{
pitch = pitch - y_difference;
}
}
//If the mouse was dragged up, move the camera up
if(new_y > old_y)
{
y_difference = old_y - new_y;
y_difference = y_difference / 20;
if(pitch > 350)
{
pitch = 0;
}
else
{
pitch = pitch + y_difference;
}
}
//Update the camera position based on the new Yaw, Pitch and Roll
cameraUpdate();
}
"camera.h"和"mouse.h"都包含在内,并且设置了这两个类的实例 -
Mouse Mouse;
Camera Camera;
我不知道可能缺少什么。
如果您想了解更多信息,请告诉我。
也许您在带有" inline
"关键字的.cpp文件中包含了moveCamera()
的定义。这可以解释为此方法是定义它的.cpp的本地方法。尝试删除inline
。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接