Something odd is happening.
I have a static library, in C, compiled using CMake.
I link against to build an executable fine on Ubuntu, but under Snow Leopard I get an undefined symbol error when I attempt to do this:
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
This is mysterious to me, because nm on the static library shows:
… (pile of stuff omitted) …
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 is unremarkable, its just a struct; and, just to repeat, this code compiles fine on my ubuntu system.
I don’t know enough about osx library linking to know what’s wrong here, but… it’s just a fragment of c code; surely this is me doing something wrong, rather than something weird with OSX.
help! 🙂
Edit:
For reference, the struct is defined:
/** 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;
};
and used:
/** Render implementation. */
int na_impl_render(struct na_Api *api) {
struct na_Gfx_Impl *impl = (struct na_Gfx_Impl *) (api->gfx->impl);
...
However, I conclude something must be screwed up badly. There is no reason (as I understand it) for the struct symbol to turn up in the static lib.
I’m not sure if this is your exact problem, but when compiling libraries statically, often times the order of the link matters. You want to make sure the lowest level functions are ordered last.