c++ - LNK2001 : unresolved external symbol "void __cdecl func1(struct Stru1 *)"

标签 c++ c visual-studio-2013 linker unresolved-external

让我编辑一下问题: 这些文件是:

file1.h
file1.c
file3.h
file2.h
file2.c
file4.h
file5.h
main_code.cpp

文件1.h

#include "file3.h"
typedef struct{} Str1;
void func1(Str1 *str1);
void func2(Str1 *str1);

文件1.c

#include "file3.h"
#include "file1.h"
#include "file2.h"
#include <stdio.h>
#include <math.h>
void func1(Str1 *str1){}
void func2(Str1 *str1){}

文件2.h

#include "file3.h"
#include "file1.h"

文件2.c

#include "file3.h"
#include "file1.h"
#include "file2.h"
#include <stdio.h>
#include <math.h>

文件3.h

Doesnt include others.

文件4.h

#include "file1.h"
#include "file2.h"
#include "file5.h"

文件5.h

#include "file3.h"

main_code.cpp

#include "file1.h"
#include "file2.h"
#include "file4.h"
#include "file5.h"
func1(variable)
func2(variable)

错误“LNK2001:无法解析的外部符号”发生在func1和func2上,所以我没有放置其他函数有什么功能。我已经尝试将包含内容放入“extern C”中,但没有成功。 如果我添加到 main_code.cpp

  #include "file1.c"

然后程序就可以运行了...

最佳答案

您很可能忘记将 file1.c 添加到项目中进行构建。

以下是您不应该在 C++ 中执行的操作:

#include "file1.h"
#include "file2.h"  
    func1(variable);
    func2(variable);
 #include "file1.c"
#include "file2.c" 

这些 #include "file1.c"/#include "file2.c"就是您的项目的用途 - 您在 IDE 中添加新文件。

关于c++ - LNK2001 : unresolved external symbol "void __cdecl func1(struct Stru1 *)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32353144/

相关文章:

c++ - 纹理未显示

c - shmat 返回 errno=13(EACCES) 的段错误

c# - 构建错误: the type or namespace name 'data' does not exist in the namespace "xxx.yyy.zzz" (are you missing an assembly reference?)

c++ - 从具有尝试限制的 txt 文件登录

c++ - 有没有办法从 VS 环境之外的 MS 单元测试框架获取信息?

c++ - 外部变量未声明

c++ - visual studio 2013如何链接opencv等dll文件输出exe

c++ - 波斯语的 QString

c++ - Linux 上是否有等效的 .def 文件来控制共享库中导出的函数名称?

c - 将新节点插入二叉树并返回其头指针