linux编译代码命令行,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!" <

#else

cout << "Build for Linux!" <

#endif

cout << "Compiler: " << g_Compiler << endl;

cout << "32 or 64: " << g_Arch <

cout << "pointer size: " << sizeof( g_Arch) << endl;

cout << "time_t size " << sizeof(time_t) << endl;

cout << "ssize_t size " << sizeof(ssize_t) << endl;

cout << "socklen_t size " << sizeof(socklen_t) << endl;

cout << "GNU version: "<< ShowMarco( __GNUC__ ) << "." << ShowMarco( __GNUC_MINOR__ ) <

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

return 0;

}

运行结果

0818b9ca8b590ca3270a3433284dd417.png

运行结果 (CentOS 6.5)

0818b9ca8b590ca3270a3433284dd417.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值