[CMake] Linking against exported symbols in an application (cross platform)

Doug douglas.linder at gmail.com
Sun Jul 15 21:11:22 EDT 2012


I've got an application that has exported a bunch of symbols in it
(specifically the lua runtime) and I've got a plugin that gets loaded
by that application that uses the symbols in the parent.

I can make it work with a bunch of annoying if(...) statements, like:

if(APPLE)
  set(MY_EXTRA_C_FLAGS "-shared -avoid-version -no-undefined
-flat_namespace -undefined suppress"
endif()

...and that seems to work, but it's extremely compiler dependent
(read: I haven't figured out how to do it on visual studio yet).

Is there a better and more portable way to be doing this?

In my specific situation I have a lua plugin (blah.lua + blah.so /
blah.dll) that needs to call the lua c runtime, but the lua runtime is
already statically linked to the parent application.

Linked against a second copy of the runtime causes crashes (deliberate
lua design issue), and the API is exposed in the application.

So I need to link the shared library / dll with missing symbols and
the right 'magical linker arguments' so that when the dll loads it
resolves the symbols from the parent.

~
Doug.


More information about the CMake mailing list