Skip to main content
gamedev.net
🔒 Locked

Cross-platform libraries

Started by CTar 3 replies 1.3k views
Original Post
CTar
CTar
Well I'm developing my game engine I have encountered a problem, creating cross-platform libraries. I started by using .def files, but I'm starting to consider using __declspec(dllexport) instead because not being able to export classes is very annoying. Currently the only advantage I can see with __declspec(dllexport) is that they can export classes(huge benefit). The only advantage I can see with .def files is that I heard they were more portable (is this true?). So could anyone give me some arguments for and against both?
S1CA
S1CA
A few thoughts:

DLLs are only a Windows PC thing, so the only portability/cross platform concerns are between different versions of Windows - and those aren't substantial. DEF files will work better with older Windows compilers.

DLL exports were designed for C functions; exporting classes from a DLL is a nasty hack IMO (as with C++ name mangling to be able to use a C linker).

COM and related technologies were invented years ago to help solve the problem of exposing shared OO objects in a robust way.

Personally, if I need to expose a class/object from a DLL I favour factory methods and similar patterns. Exposing a real constructed object is the only worthwhile thing to do from a DLL - the class itself isn't of use at runtime.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
SiCrane
SiCrane
You might want to check out how to build shared objects for *nix platforms.
CTar
CTar
Re-reading my post I see it was worded very badly. What I really meant was if it was more portable to export functions only than classes, is it for example possible to export classes in .so files?
ZQJ
ZQJ
Yes - at least in Linux (I've never used 'real' Unix) all non-static symbols are exported in C++ the same as C, so you just link against it the same as a normal object. You've just got to watch our for compiler type/version because the name mangling system (and the binary interface) must be the same otherwise it won't work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.