[英]problems when including a header file
So i'm having a problem when i try to include a header file. 所以当我尝试包含头文件时遇到了问题。 I am defining a header and including it in all of my files but i'm getting this error "unresolved external symbol "void_cdecl print(void)"(?print@@YAXXZ) referenced in function main.
我正在定义一个标头,并将其包括在我的所有文件中,但是却收到此错误“在函数main中引用的“未解决的外部符号” void_cdecl print(void)”(?print @@ YAXXZ)。
my main file TEST.cpp 我的主文件TEST.cpp
#include "stdafx.h"
#include "Header1.h"
using namespace std;
int main()
{
print();
return 0;
}
i've only made a simple print function which i define here in Source1.cpp 我只做了一个简单的打印功能,我在Source1.cpp中定义了它
#include "Header1.h"
void print() {
cout << "HELLO WORLD" << endl;
}
and my header file looks like this - Header1.h 我的头文件看起来像这样-Header1.h
#pragma once
#ifndef HEADER1_H
#define HEADER1_H
void print();
#endif
I did some research i found that this problem is often caused by spelling mistakes but i really cant see it. 我进行了一些研究,发现此问题通常是由拼写错误引起的,但我确实看不到它。
i've only made a simple print function which i define here in Source1.cpp 我只做了一个简单的打印功能,我在Source1.cpp中定义了它
this file name should be Header1.cpp 该文件名应为Header1.cpp
#include "Header1.h"
void print() {
cout << "HELLO WORLD" << endl;
}
You have a linkage problem. 您有联系问题。
You've to compile Source1.cpp and to link it. 您必须编译Source1.cpp并将其链接。
You are missing std::iostream: 您缺少std :: iostream:
#include "Header1.h"
#include <iostream>
using namespace std;
void print() {
cout << "HELLO WORLD" << endl;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.