🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

.so's (Dynamic libraries, Linux equivelent to .dll's)

Started by
0 comments, last by Zephyre 23 years, 4 months ago
Please note that this post pertains to a multiplayer server written natively for Linux. The server utilizes the dlopen() routines which only support the C stack conventions, not C++ so an export "C" { } is required. This could be the problem, but I wanna be sure. If someone could suggest an altertenative, please repond. If someone could suggest a solution, please respond. If someone wants to get me out of this horrid life that is programming, please respond. In order to provide flexibility for my game''s server, I have made it possible for all commands to be dynamically loaded from a dynamic library using the dlopen() routines. The problem I find is that my server is written in C++. I call a certain function (doCommand) which takes a few arguments, including the class of the player calling the function and the class of the entire game world. From here I call client->sendToPlayer("Hello"); which works fine. But when I call world->getZone(client->getZone())->sendToZone("Hello");, dlopen reports an error and crashes the server. Any ideas what could be causing this, or if there are any alternatives to the dlopen() routines that might support C++ natively (currently all the modules have an "export ''C''" line in them because dlopen requires the C stack conventions, unlike the C++ conventions). I might also note that client is an inherited class off of a larger Character class, and that sendToPlayer is a virtually overloaded function.
============================ Trevor "Zephyre" Barnett
Advertisement
The first time I read your post, I started writing up some code to suggest how you could load dlls and execute each function to check for commands, but now that ive re-read your post, I think your problem is when you try to "access" class''s (correct me if im wrong).

There are ways to get around this, microsoft had the same problem with directx. Its impossible to use C++ classes in dlls so they used a "COM" Interface. Im not really an expert on dynamic linking and im very new to linux programming. Ive read the man page. It seems that trying to call a non-c function from a .so library isnt allowed.

Im thinking about how you could accomplish this, but it seems difficult, there are very complex methods such as using a "message que" where have a cache of function pointers and arguments that get called during free time. You could simply use a C function to post to the message que and have your own non-dynamically (statically) linked code handle it.

You might also wanna try using a vtable inside (local to) the dynamical library and haev a function to assign these pointers to the member functions of your class. You could have a problem with not being able to access member functions though.

I cant really see any practical solutions that can solve your problem, perhaps if you made copies of all your server functions as local functions. For example:

int _dynamic_sendtozone(char *str)
{
return client->getZone()->sendToZone(str);
}

This would work, since it would allow you to dlopen() the library, and it would compile (or should) with the prototypes for those functions (the _dynamic_** ones) and those references would be resolved once yourve opened it I hope.

As ive said, these are only ideas, ive never used linux dynamic linking and i could be completely wrong. Your game sounds very interesting and id really like to see a demo, or maybe help out if your looking for help. (Im quite experienced with windows coding and im learning unix by re-building a server I made for windows in linux)

My email is CorsairK8@Fnemesis.com, your game sounds good and id really like to see it.

CorsairK8

This topic is closed to new replies.

Advertisement