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

 最近 要进行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 编译版本   __GNUC__   主版本号      __GNUC_MINOR__   次版本号

__x86_64__ 64位平台编译。 _WIN32 windows 平台编译。

#include 
using namespace std;
#include 
#include 



#ifdef __GNUC__
  const char * g_Compiler = "GNU_C";
#else
  const char * g_Compiler = "UNKNOWN_C";
#endif



#ifndef __x86_64__
  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()
{
    #ifdef _WIN32
      cout << "Build for Windows OS!" <

   运行结果

      Linux GCC 开发入门(一) -- 使用makefile 命令行编译_第1张图片

     运行结果 (CentOS 6.5)

     Linux GCC 开发入门(一) -- 使用makefile 命令行编译_第2张图片

6.  makefile 的 使用。

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

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

clean:
	rm -f test


 

 



你可能感兴趣的:(Linux开发)