学习C++ primer plus第九章的两个文件链接的问题

nnh 2006-09-07 10:56:48
程序清单9.6:

// twofile1.cpp -- variables with external and internal linkage
#include <iostream> // to be compiled with two file2.cpp
int tom = 3; // external variable definition
int dick = 30; // external variable definition
static int harry = 300; // static, internal linkage

// function prototype
void remote_access();

int main()
{
using namespace std;
cout << "main() reports the following addresses:\n";
cout << &tom << " = &tom, " << &dick << " = &dick, ";
cout << &harry << " = &harry\n";
remote_access();
system("pause");
return 0;
}


程序清单9.7:

// twofile2.cpp -- variables with internal and external linkage
#include <iostream>
extern int tom; // tom defined elsewhere
static int dick = 10; // overrides external dick
int harry = 200; // external variable definition,
// no conflict with twofile1 harry

void remote_access()
{
using namespace std;
cout << "remote_access() reports the following addresses:\n";
cout << &tom << " = &tom, " << &dick << " = &dick, ";
cout << &harry << " = &harry\n";
}

书上说要对这两个文件进行链接才可调试.我用的是Dev-C++调试器,不会做呀?谢大家帮忙.
...全文
254 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
OOPhaisky 2006-09-07
  • 打赏
  • 举报
回复
楼主最好到linux下面去试验,或者安装一个mingw(这个是windows版本的gcc)。
然后分别将两个源文件(twofile1.cpp和twofile2.cpp)编译为两个目标文件(obj文件),然后用连接器ld将两个目标文件链接成为一个可执行文件。
nnh 2006-09-07
  • 打赏
  • 举报
回复
那需要用什么软件呢?我只安装了Dev-C++呀.
sinall 2006-09-07
  • 打赏
  • 举报
回复
放在一个工程编译就可以了吧。
或者
g++ twofile1.cpp twofile2.cpp

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧