最近 要進行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 <iostream>
using namespace std;
#include <time.h>
#include <sys/socket.h>
#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!" <<endl;
#else
cout << "Build for Linux!" <<endl;
#endif
cout << "Compiler: " << g_Compiler << endl;
cout << "32 or 64: " << g_Arch <<endl;
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__ ) <<endl;
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