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

2017年7月12日 星期三

cross compiler的interpreter

通常corss compiler for ARM有可能都會用到arm-linux-gnueabihf-gcc or arm-linux-gnueabi-gcc,
是由 Linaro 公司基于GCC推出的的ARM交叉编譯的工具

cross compiler前,最好先確認目標板子的interpreter是什麼~
$ file hello 
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=97943e1e425eadf112294e3fd26d10c5649b1d1b, with debug_info, not stripped
有可能是ld-linux.so.3, or ld-linux-armhf.so.3 or 其它
$ ls -alh /lib/ld*
lrwxrwxrwx 1 root root 30  6月 17  2017 /lib/ld-linux-armhf.so.3 -> arm-linux-gnueabihf/ld-2.19.so                                                                                                  
這片目標板,就是用arm-linux-gnueabihf,如上

x86的應該都是像下面這樣
$ ls -alh /lib/ld*
lrwxrwxrwx 1 root root 30  6月 17  2017 /lib/ld-linux.so.2 -> /lib32/ld-linux.so.2

如果弄混了,通常都不能執行
$ ./hello
sh: ./hello: not found


至於安裝arm-linux-gnueabihf,ubuntu通常用apt就行了
$ sudo apt-get install gcc-arm-linux-gnueabihf

手動安裝~載點:
a. 4.8-2013.12, 可以直接用的
b. 其它版本: 官方載點

gcc-linaro-armeb-linux-gnueabihf:  Big-endian
gcc-linaro-arm-linux-gnueabihf: Little-endian


LDFLAGS:指定include位置LIBS: 指定用lib, ex: -lm, -lasound
CFLAGS: C, 指定C include位置,ex: CFLAGS=-I/usr/include
CPPFLAGS: C++, 指定C++ include位置

2012年1月12日 星期四

static link & Dynamic Link & Dynamic Load

【轉貼】 一天一成長
Static link:
Compiler時,library加入程式碼
優:快
劣:佔空間
Dynamic Link:
Compiler時,不將library加入程式碼,執行程式的時後,再將 library載入程式碼,若有多個程式共用同一個library,只需載一個library進memory
優:省空間
劣:慢
Dynamic Load:
Compiler時,不將library加入程式碼,執行程式時,遇到函式,才將library載入,用完後再free出空間
優:更省空間
劣:更慢
==========================
Static Link
Creating a Static Library:
  1. Compile source codes
    # gcc –c file1.c file2.c file3.c
  2. Create a static library named libmylib.a
    # ar rcs libmylib.a file1.o file2.o file3.o
    -r: 新增 *.o 到 libfun.a 中
    -c: 建立新的程式庫
    -s: 將一個 object 檔的 index 寫入程式庫
  3. Using a Static Library:
    # gcc –o main main.c –L. –lmylib (lib不用打)
    Parameters:
    -L: the directory of the library
    -l: the name of the library
Dynamic Link
Creating a Shared Library:
  1. Compile source codes
    # gcc -c file1.c file2.c file3.c
    or
  2. 加上-fPIC用來產生position-independent code # gcc -c -fPIC file1.c file2.c file3.c
  3. Create a shared library named libmylib.so
    # gcc -shared -o libmylib.so file1.o file2.o file3.o
  4. Using a Shared Library:
    # gcc –o main main.c –L. –lmylib
    Note: Remember to put libmylib.so into PATH, ex. /usr/lib
Dynamic Load (還沒用過)
Creating a Shared Library:
  1. Compile source codes;
    # gcc –c file1.c file2.c file3.c
  2. Create a shared library named libmylib.so
    # gcc -shared -o file1.o file2.o file3.o libmylib.so
  3. Using a Shared Library:
    (Reference: http://linux.die.net/man/3/dlopen)
    Use the following function to access the shared library:
    #include <dlfcn.h>
    void *dlopen(const char *filename, int flag);
    char *dlerror(void);
    void *dlsym(void *handle, const char *symbol);
    int dlclose(void *handle);
    Compile: Since above function are implemented in the library libdl.a, we need to load this library
    # gcc dltest.c –ldl
    Parameters:
    -ldl: load the library libdl.a
ref:

2009年9月21日 星期一

使用 math.h 注意事項

使用 math.h 注意事項

#include

double ceil(double x);
float ceilf(float x);
long double ceill(long double x);

Link with -lm.

ex: gcc abc.c -o abc -lm

ref:
Linux man page

2008年12月14日 星期日

安裝 gcc

安裝 gcc

1. apt-get update
2. aptitude install gcc
3. aptitude install build-essential (library)

安裝 GTK

安裝 GTK (感謝 Bruce 提供)

0. apt-get update
( aptitude install gcc )
1. aptitude install build-essential ( library for C)
2. aptitude install gnome-devel
3. aptitude install gnome-dev-doc


PS: 程式寫好後Compiler :
gcc gtkhello.c -o gtktest `pkg-config --cflags --libs gtk+-2.0`

疑似可以 static link@@
gcc showpict.c -L /usr/lib/ `pkg-config --cflags --libs gtk+-2.0` -o showpict

p.s :
g_thread_init 在 gthread-2.0 庫中,
在 pkg-config 中除了 gtk+-2.0 之外還需要加上 gthread-2.0 一項
gcc gtkhello.c -o gtktest `pkg-config --cflags --libs gtk+-2.0 gthread-2.0`