首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

多文件组织 有关问题

2012-03-21 
多文件组织 问题C/C++ code//hello.h#ifndefHello_HH#defineHello_HHvoid HelloWorld() #endif//HelloWor

多文件组织 问题

C/C++ code
//hello.h#ifndef  Hello_HH#define  Hello_HHvoid HelloWorld(); #endif//HelloWorld.cpp#include <iostream>#include "hello.h"using namespace std;void HelloWorld(){    cout<<"yes,Hello World"<<endl;}//main.cpp#include <iostream>#include "hello.h"using namespace std;int main(){    cout<<"Before hello world!"<<endl;    HelloWorld();    cout<<"After hello world"<<endl;    return 0;}

怎么会出现 error LNK2001: unresolved external symbol "void __cdecl HelloWorld(void)" (?HelloWorld@@YAXXZ)

[解决办法]
怎么编译的?
helloworld.cpp 是否一起编译了?
[解决办法]
//hello.h 要把HelloWorld.cpp 放过去 不是函数定义
[解决办法]
HelloWorld.cpp
是不是不在工程里,新建的文体要添加到里,才会一起编译。

如果添加了先clean一下在rebuild all试试

[解决办法]
C/C++ code
//hello.h#ifndef  Hello_HH#define  Hello_HHextern void HelloWorld();//这也该一下 #endif 

热点排行