利用makefile文件来编译C++
2015-09-28 10:59
417 查看
</pre><pre name="code" class="cpp"> 1 //file_NO1:hello.cpp 2 #include<iostream> 3 #include"hello.h" 4 using namespace std; 5 hello::hello() 6 { 7 } 8 9 int hello::Display() 10 { 11 cout<<"Hello, World!\n"<<endl; 12 return 0; 13 }
1 //file_NO2:hello.h 2 #ifndef HELLO_H 3 #define HELLO_H 4 class hello{ 5 public: 6 hello(); 7 int Display(); 8 }; 9 #endif
1 //file_NO3:myfirst.cpp 2 #include <iostream> 3 #include"hello.h" 4 //using namespace std; 5 6 int main() 7 { 8 hello theHello; 9 theHello.Display(); 10 //cout<<"Hello"<<endl; 11 return 0; 12 }
在终端输入:vim makefile
makefile文件如下:
1 myfirst11:myfirst.o hello.o 2 g++ myfirst.o hello.o -o myfirst11 3 hello.o:hello.cpp 4 g++ -c hello.cpp -o hello.o 5 myfirst.o:myfirst.cpp 6 g++ -c myfirst.cpp -o myfirst.o
最后,再在终端输入:./myfirst11即可得到输出结果。
在ubuntu下面进行普通的编译和链接见前文博客里面的过程:解决C++编译出现的重定义问题:multiple definition of ’XXX‘错误
参考资料:Linux下GCC和Makefile实例(从GCC的编译到Makefile的引入)
相关文章推荐
- C++ sort vector<vector<int> > or vector<MyClass> 容器的排序
- C++学习笔记25,析构函数总是会宣布virtual
- C++中局部静态变量的调用问题
- C语言:排序算法
- C++ int main(int argc,char* argv[])详解
- c++笔试题-输入n,输出对应的所有长度为n的二进制串
- C/C++语言杂谈
- C++ 墙角知识 04
- c++ typedef类型定义
- c++ 初始化
- 黑马程序员——C语言日志——typedef的使用以及和#define的区别
- C++ STL简化了编程
- 【Visual C++ 2010】如何快速将Win32程序改为控制台程序
- C++ OOP面向对象
- 解决C++编译出现的重定义问题:multiple definition of ’XXX‘错误
- 为什么C++中空类和空结构体大小为1?(转载)
- C语言链表常见基本操作
- 【Visual C++ 2010】Unicode和ANSI的一些注意事项
- C++学习笔记1--基础知识
- 【转】最值得你所关注的10个C语言开源项目