Advertisement

SharedLibraries

Started by August 20, 2001 09:08 AM
0 comments, last by FloViel 23 years ago
Is it possible to create C++ SharedLibraries under Linux?? I''ve tried it and creation worked but when I wanted to load a function via "dlsym" it failed with the error: "Symbol not found". When I use C as the programming language everything works fine. What am I doing wrong?
Visit:http://www.evildawncrew.comAll things which are worth beeing done, are worth beeing donw well.
The problem you get is that C++ is prone to name-mangling. In other words, it doesn''t export a function foo, but rather a function "foo@VQAAH" or something like that. C++ does that in order to be type-safe - those additional characters somehow represent the argument and return value types.

To prevent that, simply prefix your function declarations with extern "C", or put all your function headers in something like this:

  #if defined(__cplusplus)extern "C" {#endif// Your function decls go here...#if defined(__cplusplus)};#endif  


cu,
Prefect

One line of sourcecode says more than a thousand words.
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement