红联Linux门户
Linux帮助

Linux GCC开发入门--使用makefile命令行编译

发布时间:2016-06-29 15:03:02来源:linux网站作者:phil_gu

最近要进行Linux 下编写一个视频处理的程序。以前没有接触过linux开发,现在将自己每一步的过程,记录下来。不够肯定会有很多错误了。以后慢慢修正了。


1.安装 Linux-- Ubuntu 16.04 LTS.


2.开发环境:网上推荐的很多,自己认为codeblocks, eclipse 比较好。


3.Eclipse 先慢慢装:

$sudo apt-get install eclipse-cdt  eclipse 


4.不等 结束,先用命令行,编译个小程序.

命令: 

gcc test.cpp -o test -lstdc++ 
or 
g++ test.cpp -o test 


5.GCC 编译版本和属性。

确认一下 平台属性。 一个宏定义。

#include <iostream> 

using namespace std;

#ifdef __GNUC__ 
const char * g_Compiler = "GNU_C"; 
#else 
const char * g_Compiler = "UNKNOWN_C"; 
#endif 
 
// Define _W64 macros to mark types changing their size, like intptr_t. 
#ifndef _W64 
const char * g_Arch = "x86_32"; 
#  else 
const char * g_Arch = "x86_64"; 
#endif 

#define  _ShowMarco( x )#x 
#define  ShowMarco( x ) _ShowMarco( x) 

int main() 

cout << "Compiler: "  << g_Compiler << endl; 
cout << "32 or 64: "  << g_Arch <<endl; 

cout << "GNU value:  "  << ShowMarco( __GNUC__ ) <<endl; 

cout << "Hello World!" << endl; 
return 0; 

运行结果:

Linux GCC开发入门--使用makefile命令行编译


6.makefile 的使用。

CC= g++ 
INC_PATH  = ../../include 
CFLAGS = -I $(INC_PATH) 
LDFLAGS   = -lm -ldl -lpthread 

test: test.cpp 
$(CC) -o test test.cpp  $(CFLAGS) $(LDFLAGS) 

clean: 
rm -f test


本文永久更新地址:http://www.linuxdiyf.com/linux/21938.html