OSX:当存在所述符号时,C中的未定义符号

时间:2011-02-28 05:41:22

标签: c macos

发生了奇怪的事情。

我有一个静态库,在C中,使用CMake编译。

我链接反对在Ubuntu上构建一个可执行文件,但在Snow Leopard下,当我尝试这样做时,我得到一个未定义的符号错误:

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

这对我来说很神秘,因为静态库上的nm显示:

...(遗漏了一堆东西)......

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);
  ... 

但是,我总结说必须严厉打击。没有理由(据我理解)结构符号在静态库中出现。

1 个答案:

答案 0 :(得分:0)

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