最近 要进行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;
}
运行结果
运行结果 (CentOS 6.5)
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