g++编译链接多个文件
来源:互联网 发布:服务器端软件有什么 编辑:程序博客网 时间:2024/05/15 10:58
头文件 mystack.h
/** * File mystack.h * Declare class Stack **/#ifndef MYSTACK_H#define MYSTACK_H#include <iostream>using namespace std;enum Error_code { success, fail, underflow, overflow };typedef char Stack_entry;const int maxstack = 10;class Stack{public: Stack(); bool empty() const; Error_code pop(); /** * the top of the Stack is returned in item **/ Error_code top(Stack_entry& item) const; Error_code push(const Stack_entry& item); private: int count; Stack_entry entry[maxstack];};#endif
预编译: g++ mystack.h
库文件 mystack.cpp
/** * File mystack.cpp **/#include "mystack.h"#include <iostream>using namespace std;Error_code Stack::push(const Stack_entry& item){ Error_code outcome = success; if (count >= maxstack)outcome = overflow; elseentry[count++] = item; return outcome;}Error_code Stack::pop(){ Error_code outcome = success; if (count == 0)outcome = underflow; elsecount--; return outcome;}Error_code Stack::top(Stack_entry& item) const{ Error_code outcome = success; if (count == 0)outcome = underflow; elseitem = entry[count - 1]; return outcome;}bool Stack::empty() const{ bool outcome = true; if (count < 0)outcome = false; return outcome;}Stack::Stack(){ count = 0;}编译:g++ -c mystack.cpp -o mystack.o
main函数: stacktest.cpp
/** * File stacktest.cpp **/#include "mystack.h"#include <iostream>using namespace std;int main(){ Stack s; s.push('1'); char top = 0; s.top(top); cout << top << endl; return 0;}
编译并链接: g++ -o stacktest stacktest.cpp ./mystack.cpp
运行: ./stacktest
- g++编译链接多个文件
- g++编译多个相关文件,
- g++编译连接多个文件
- gcc和g++区别,使用g++编译多个文件
- g++编译链接文件基础中的基础
- g++如何编译多个原文件和头文件
- g++如何编译多个原文件和头文件
- g++如何编译多个原文件和头文件
- g++多文件编译
- 文件包含---多个源程序的编译和链接
- 多文件编译、链接
- g++ 编译和链接
- g++ 编译和链接
- g++ 编译和链接
- g++编译 链接 执行
- g++ 编译和链接
- g++ 编译和链接
- gcc g++ 编译链接
- oracle的stored outline的创建与维护
- 快绝望了
- Vim多文件查找与替换
- 问题解决总结1_ivf上imsl的安装及使用
- C++ Primer 第一章 快速入门笔记
- g++编译链接多个文件
- uva oj 457
- C语言指针学习(一) ---- 指针是什么
- 软考(1)--数据结构
- 2011东软校园招聘笔试题部分知识点总结——语言部分(JAVA)
- 浪潮之巅-互联网的前世今生
- 帧缓冲设备(framebuffer)
- prum算法介绍
- 小团聚