2013-04-28 92 views
3

我正在試着學習一些libuv,看起來有一本很棒的書能夠通過它。但是,這本書並沒有解釋如何實際編譯它。我在github上編譯的代碼上運行make,並使用GYP編譯(https://github.com/joyent/libuv)。不過,我不確定需要包含哪些類庫才能獲得編譯代碼。我試圖編譯此代碼:庫在os上編譯libuv?

gcc -o first first.c build/Release/libuv.a 

和我得到了以下缺失的符號:

Undefined symbols for architecture x86_64: 
    "_CFArrayCreate", referenced from: 
     _uv__fsevents_init in libuv.a(fsevents.o) 
    "_CFRunLoopAddSource", referenced from: 
     _uv__cf_loop_runner in libuv.a(darwin.o) 
    "_CFRunLoopGetCurrent", referenced from: 
     _uv__cf_loop_runner in libuv.a(darwin.o) 
    "_CFRunLoopRemoveSource", referenced from: 
     _uv__cf_loop_runner in libuv.a(darwin.o) 
    "_CFRunLoopRun", referenced from: 
     _uv__cf_loop_runner in libuv.a(darwin.o) 
    "_CFRunLoopSourceCreate", referenced from: 
     _uv__platform_loop_init in libuv.a(darwin.o) 
    "_CFRunLoopSourceSignal", referenced from: 
     _uv__cf_loop_signal in libuv.a(darwin.o) 
    "_CFRunLoopStop", referenced from: 
     _uv__platform_loop_delete in libuv.a(darwin.o) 
    "_CFRunLoopWakeUp", referenced from: 
     _uv__cf_loop_signal in libuv.a(darwin.o) 
    "_CFStringCreateWithCString", referenced from: 
     _uv__fsevents_init in libuv.a(fsevents.o) 
    "_CFStringGetSystemEncoding", referenced from: 
     _uv__fsevents_init in libuv.a(fsevents.o) 
    "_FSEventStreamCreate", referenced from: 
     _uv__fsevents_init in libuv.a(fsevents.o) 
    "_FSEventStreamInvalidate", referenced from: 
     _uv__fsevents_close in libuv.a(fsevents.o) 
    "_FSEventStreamRelease", referenced from: 
     _uv__fsevents_close in libuv.a(fsevents.o) 
    "_FSEventStreamScheduleWithRunLoop", referenced from: 
     _uv__fsevents_schedule in libuv.a(fsevents.o) 
    "_FSEventStreamStart", referenced from: 
     _uv__fsevents_schedule in libuv.a(fsevents.o) 
    "_FSEventStreamStop", referenced from: 
     _uv__fsevents_close in libuv.a(fsevents.o) 
    "_kCFRunLoopDefaultMode", referenced from: 
     _uv__cf_loop_runner in libuv.a(darwin.o) 
     _uv__fsevents_schedule in libuv.a(fsevents.o) 
ld: symbol(s) not found for architecture x86_64 
collect2: ld returned 1 exit status 

可有人

/* first.c */ 
#include <stdio.h> 
#include <uv.h> 

int main() { 
    uv_loop_t *loop = uv_loop_new(); 

    printf("Now quitting.\n"); 
    uv_run(loop, UV_RUN_DEFAULT); 

    return 0; 
} 

我用下面的命令從libuv文件夾編譯它給我一個關於如何構建libuv的快速教程,或者如果還有其他我需要的東西?

回答

4

好的,算出來了。我必須使用OSX「CoreFoundation」和「CoreServices」框架。以下命令編譯成功:

gcc -o first first.c build/Release/libuv.a -framework CoreFoundation -framework CoreServices 
1

感謝您的解決方案 - 我一直在努力解決同樣的問題。

我開發你的答案,這樣我可以編譯和使用下列選項中的任何文件夾鏈接:

gcc -o first -L/my/folders/libuv/ -I/my/folders/libuv/include/ first.c -luv -framework CoreFoundation -framework CoreServices 

而且,我加入了圖書館爲Eclipse中使用以下步驟:

將路徑添加到頭文件uv.h中:

右鍵單擊項目並選擇屬性 - > C/C++常規 - >路徑和符號 - >包括 。點擊添加..,並在文本框中輸入:

/my/folders/libuv/include/ 

點擊適用─>好吧

添加庫:

而在同一屏幕,如上,點擊。點擊添加..,並在文本框中輸入:

uv 

到路徑添加到庫中:

仍對庫路徑同一屏幕上點擊。點擊添加..,並輸入在文本框中:

/my/folders/libuv/ 

要添加的框架:

項目上單擊鼠標右鍵屬性 - > C/C++建設 - >設置 - >工具設置 - > Miscellaneous-> Mac OS X C++ Linker。然後在標題鏈接器標記添加文本框:

-framework CoreFoundation –framework CoreServices 

點擊應用再建。

5

隨着通過自制安裝libuv做:

$ gcc -luv main.c 
0

您可以使用GYP來生成libuv的xcodeproj(如libuv的README解釋),這xcodeproj添加到您的主Xcode項目。

它可以自動的(便於更新)用一個簡單的shell腳本(假定你把libuv子模塊Externals/libuv,但可以更改):

git submodule update --init 
git clone https://chromium.googlesource.com/external/gyp.git Externals/libuv/build/gyp 
Externals/libuv/gyp_uv.py -f xcode 

然後你就可以添加libuv作爲一個依賴和庫到你的目標鏈接到:

Xcode configuration

的最後一件事做的是告訴Xcode中哪裏libuv的標題:

Headers configuration

See this post