2011-02-28 47 views
1

发生了一些奇怪的事情。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); 
    ... 

然而,我的结论必须采取某种严重搞砸了。根据我的理解,没有任何理由要在静态库中创建结构符号。

+0

这里要做一些说明,静态库的代码布局是:impl.c,desktop.gfx.c,desktop.gfx.h。 struct na_Gfx_Impl {...}在desktop.gfx.h中定义,其中包含impl.c – Doug 2011-02-28 05:49:48

+2

man nm实际上会告诉你名称旁边的神秘'U'字符表示符号是未定义。 – 2011-02-28 05:50:15

+0

啊,是的,我没注意到。问题是,为什么?这只是头文件中的一个结构。 – Doug 2011-02-28 05:51:46

回答

0

我不确定这是否是确切的问题,但静态编译库时,通常链接的顺序很重要。你想确保最低级别的功能是订购最后

+0

如果一个简单的结构导致链接错误,那么@ user353820可能有更大的问题。 – 2011-02-28 14:32:56