參考文章:
以及討論帖:
摘要:cygwin下gcc只能使用.dll動態庫,不能使用.so型別的動態庫,所有在用gcc建立動態庫的時候,-o的引數指定的動態庫的名字需要為lib***.dll。
具體例項:
// so_test.h
#include "stdio.h"
void test_a();
$ gcc test_a.c -fpic -shared -o libtest.dll// test_a.c
#include "so_test.h"
void test_a()
$ gcc test.c -l. -ltest -o test// test.c
#include "so_test.h"
int main()
----------------------------
引數說明:
-l:表示要連線的庫在當前目錄中,
-ltest:編譯器查詢動態連線庫時有隱含的命名規則,即在給出的名字前面加上lib,後面加上.dll(cygwin)(
linux環境中是.so)來確定庫的名稱
執行效果:
$ ./test.exe
this is in test_a...
注意:最後要注意的問題是,該test程式時,可能會提示 error while loading shared libraries: libtest.so: cannot open shared object file: no such file or directory
解決方法:指定ld_library_path為libtest.dll所在目錄
gcc建立和使用靜態庫 動態庫
gcc建立和使用靜態庫 動態庫 下面以工程libtest為例說明gcc 建立和使用 靜態庫 動態庫的過程,libtest目錄結構和內容如圖1所示,其中三個檔案hello.h,hello.c和main.c的內容如下。libtest include hello.h ifdef hello h defin...
gcc建立和使用靜態庫 動態庫
下面以工程libtest為例說明gcc建立和使用靜態庫 動態庫的過程,libtest目錄結構和內容如圖1所示,其中三個檔案hello.h,hello.c和main.c的內容如下。圖1libtest include hello.h ifdef hello h define hello h void h...
在cygwin下安裝gcc4 0
1 首先在 2 使用winrar把gcc 4.0.0.tar.gz解壓在安裝目錄下 c temp gcc 4.0.0 比在linux下容易多了,呵呵。3 建立目標目錄 c temp build 4 配置安裝引數,通過在cygwin執行安裝目錄下的configure來配置,由於我只是測試所以太多的引數...