發生了一些奇怪的事情。OSX:當所述符號存在時,C中未定義的符號
我有一個靜態庫,在C中,使用CMake編譯。
我對鏈接的基礎上Ubuntu的一個可執行罰款,但在雪豹,我得到一個未定義符號錯誤,當我試圖做到這一點:
per-ms006:mbuild douglasl$ make
Linking C executable Sample
Undefined symbols:
"_na_Gfx_Impl", referenced from:
_na_impl_render in libdesktop.a(impl.c.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [Sample] Error 1
make[1]: *** [CMakeFiles/Sample.dir/all] Error 2
make: *** [all] Error 2
這是神祕的對我來說,因爲在靜態納米庫顯示:
...(一堆東西略)......
libdesktop.a(impl.c.o):
0000000000003a30 s EH_frame1
0000000000003990 s LC0
00000000000039a0 s LC1
00000000000039ac s LC2
00000000000039d0 s LC3
00000000000039f0 s LC4
00000000000039fc s LC5
0000000000003a0c s LC6
0000000000003a1b s LC7
0000000000003a2a s LC8
U _SDL_PollEvent
U _free
U _malloc
U _na_Gfx_Impl <----------- Symbol is there.
0000000000000209 T _na_impl_api
0000000000003b38 S _na_impl_api.eh
U _na_impl_assets_create
U _na_impl_events_create
U _na_impl_events_destroy
U _na_impl_gfx_create
U _na_impl_gfx_destroy
0000000000000124 T _na_impl_init
0000000000003aa8 S _na_impl_init.eh
0000000000000021 T _na_impl_log
0000000000003a78 S _na_impl_log.eh
0000000000000159 T _na_impl_poll
0000000000003ad8 S _na_impl_poll.eh
00000000000002d0 T _na_impl_release
0000000000003b68 S _na_impl_release.eh
000000000000018e T _na_impl_render
0000000000003b08 S _na_impl_render.eh
U _na_impl_shared_assets_destroy
U _na_impl_shared_error
0000000000000000 T _na_impl_version
0000000000003a48 S _na_impl_version.eh
U _printf
U _putchar
U _vprintf
na_Gfx_Impl是不起眼的,它只是一個結構;並且,只需重複一遍,這段代碼可以很好地編譯我的ubuntu系統。
我不知道osx庫鏈接知道這裏有什麼問題,但是......它只是c代碼片段;當然,這是我做錯了什麼,而不是OSX的奇怪。
幫助! :)
編輯:
以供參考,該結構的定義:
/** Implementation struct. */
struct na_Gfx_Impl {
/** Parent. */
struct na_Gfx *gfx;
/** SDL surface for rendering. */
SDL_Surface *screen;
/** Handler for sprites. */
struct na_utils_SetHandler *key;
/** Set of texture values. */
GLfloat *texture;
/** Set of vextex values. */
GLfloat *vertex;
};
和使用:
/** Render implementation. */
int na_impl_render(struct na_Api *api) {
struct na_Gfx_Impl *impl = (struct na_Gfx_Impl *) (api->gfx->impl);
...
然而,我的結論必須採取某種嚴重搞砸了。根據我的理解,沒有任何理由要在靜態庫中創建結構符號。
這裏要做一些說明,靜態庫的代碼佈局是:impl.c,desktop.gfx.c,desktop.gfx.h。 struct na_Gfx_Impl {...}在desktop.gfx.h中定義,其中包含impl.c – Doug 2011-02-28 05:49:48
man nm實際上會告訴你名稱旁邊的神祕'U'字符表示符號是未定義。 – 2011-02-28 05:50:15
啊,是的,我沒注意到。問題是,爲什麼?這只是頭文件中的一個結構。 – Doug 2011-02-28 05:51:46