【发布时间】:2013-07-14 12:56:13
【问题描述】:
查看下方评论以获取更新
这是错误报告: Cube_Life.obj:错误 LNK2019:未解析的外部符号“void __cdecl Draw_Coordinates(void)”
请不要让我搜索,我搜索了但找不到解决方案。我有一个 Help_Functions.h 和一个 Help_Functions.cpp,它们的内容如下所示。
我在 .h 文件中声明了函数 Draw_Coordinates 并在 .cpp 中定义了它,但我仍然不断收到错误消息。即使右键单击该功能并选择显示定义,它也只是显示搜索结果,找不到定义。
我什至尝试了像 void test(){return;} 这样的简单函数,但仍然是同样的问题。它们也不排除在构建之外。
Help_Functions.h
#pragma once
#include "stdafx.h"
void test();
void Draw_Coordinates();
Help_Functions.cpp:
#include "stdafx.h"
void test(){return;}
void Draw_Coordinates()
{
//definition, it would be unnecessary to put all that code
}
stdafx.h:
#pragma once
#define PI 3.14159265359
#include "targetver.h"
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <tchar.h>
#include <math.h>
#include <windows.h> // Standard Header For Most Programs
#include <gl/gl.h> // The GL Header File
#include <GL/glu.h>
#include <gl/glut.h> // The GL Utility Toolkit (Glut) Header
#include <stdlib.h>
#include <iostream>
#include "OBJECT_3D.h"
#include "Help_Functions.h"
using namespace std;
奇怪的是 OBJECT_3D 没有引起任何问题。我能想到的唯一区别是它的文件是由 Visual Studio 创建的,但 Help_Functions 是由我单独创建的。
【问题讨论】:
-
我不确定您为什么将这些标头放在 stdafx.h 中。至少应该在 Help_Functions.cpp 中包含“Help_functions.h”
-
嗯,这样可以减少混乱。我将.h文件添加到实现文件中但仍然没有解决。
-
这没有任何意义。我创建了一个名为“Helper”的类,并将 Helper_Functions 的内容复制到 Helper 的 .h 和 .cpp 文件中。现在它起作用了。但是,如果我删除“Helper”文件,即使使用 Help_Functions 中的代码,它也会停止工作。我想我快疯了。
-
好的,这真是太疯狂了。当我将“Help_Functions.cpp”重命名为其他任何名称时,它可以工作。出于某种原因,当我保留其原始名称或将其重命名为“Help_Functions.cpp”时,它停止工作。
标签: c++ visual-studio-2010 visual-c++ linker header-files