顯示具有 GCC 標籤的文章。 顯示所有文章
顯示具有 GCC 標籤的文章。 顯示所有文章

2012年4月17日 星期二

[GCC][Create and Use Shared Library]

This is only the record of the content of the book I read.

gcc -fPIC -c initapi.c
gcc -fPIC -c randapi.c

gcc -shared initapi.o randapi.o -o libmyrand.so

gcc main.c -L. -lmyrand -o main

export LD_LIBRARY_PATH=./

If we wanted to load this shared library dynamically.

cp libmyrand.so /usr/local/lib

2012年3月12日 星期一

[Linux][Ubuntu][Update GCC Version]

偶爾會碰到一些 GCC 4.6 版本的要求,雖然用舊有的 4.4.3 也可以做。

不過這次就趁勢升級一下好了。

由 sudo apt-get install 並沒辦法升級,所以要先

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.6
sudo apt-get install g++-4.6

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20

這兩道指令最後的「20」應該是 priority,但為什麼給定 20,目前還不清楚。

當 update-alternatives 的選擇是設定為 auto 時,會去看 priority 的值,值越大越優先。

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

最後這兩道指令都會出現「There is only one alternative in link group gcc: /usr/bin/gcc-4.6」。

所以應該是可打可不打吧。

所有指令完成後就可以發現自己的「gcc --version」和「g++ --version」顯示出「現在最新」的 4.6.2 囉。

Reference:
http://superuser.com/questions/310809/how-can-i-update-gcc-to-the-latest-version-in-ubuntu-10-04

2011年12月22日 星期四

[Linux][Ubuntu][GCC -save-temps & -fsyntax-only]

假設今天有個檔案叫 test.c。

今天我執行 gcc -save-temps test.c 後,會產生底下幾個檔案:

test.i test.o test.s 和 a.out。

就不用費神的去輸入 gcc -S 得 test.s 之類的。

而 gcc -fsyntax-only 則只會檢查語法而已,像是少打個 ; 或之類的。

不會做 pre-processing,assembling,compiling 或 linking。

至於 function name 打錯那一類的他不會有反應。

Reference:
O'Reilly .