• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
CRYP7IK

Exporting and the issues that transpire!

6 posts in this topic

Hey all,

 

I would like to start a discussion on the ever present issue that I am sure all programmers must face at some point, the issue or warning of exporting classes that contain standard template library classes; for example std::vector and std::string.  What do you think the most efficient, platform agnostic and cost effective solution is?

 

The first solution that comes to my mind is to just re-write aspects of the STL that you want to use.

 

Pros:

  • Full control
  • Probably faster (But situational)
  • No problems exporting your own classes
  • Can be thread friendly
  • Easier to debug

Cons:

  • Very cost in-effective
  • Needs a lot of testing

 

Another solution is to just ignore it and build different libraries for different implementations, so use msvc, gcc, clang and name your libraries after what they were compiled with. E.g. MyLibWindows64MSVC or MyLibWindows32GCC

 

Pros:

  • Very cost effective
  • Full usage of stl

Cons:

  • Hard for clients to use

 

How have you solved this problem or how would you solve this problem?

0

Share this post


Link to post
Share on other sites

Since there is no "correct" answer, I will share my experience.

 

I only use STL to implement the library, I don't expose STL to public API.

 

If a function returns a string, I will return a char * rather than std::string.

 

Also even if STL is platform independent, I would not expose a function to return a list or vector.

If you return a list or vector, the user can do much more than you expect, such as insert an invalid object, etc.

I would simply wrap a list or vector to simple non-template class to access the elements and element count.

0

Share this post


Link to post
Share on other sites

[quote name='CRYP7IK' timestamp='1357798392' post='5019784']
Another solution is to just ignore it and build different libraries for different implementations, so use msvc, gcc, clang and name your libraries after what they were compiled with. E.g. MyLibWindows64MSVC or MyLibWindows32GCC
[/quote]You have to do that anyway -- the C++ ABI (e.g. name mangling) isn't portable across compilers, so a library built by one compiler very likely just wont work with another compiler, no matter how simple/complex the interface is.

 

Personally, if I can't get the source to a C++ library that I want to use, then I don't use it. Even if I can get a binary that was built for my compiler, maybe I'll want to switch compilers later and the library author will have disappeared, leaving me stuck.

2

Share this post


Link to post
Share on other sites

Another solution is to just ignore it and build different libraries for different implementations, so use msvc, gcc, clang and name your libraries after what they were compiled with. E.g. MyLibWindows64MSVC or MyLibWindows32GCC

You have to do that anyway -- the C++ ABI (e.g. name mangling) isn't portable across compilers, so a library built by one compiler very likely just wont work with another compiler, no matter how simple/complex the interface is.

 

 

Personally, if I can't get the source to a C++ library that I want to use, then I don't use it. Even if I can get a binary that was built for my compiler, maybe I'll want to switch compilers later and the library author will have disappeared, leaving me stuck.

But that is not an luxury that you always get.

Edited by BornToCode
1

Share this post


Link to post
Share on other sites
Personally, if I can't get the source to a C++ library that I want to use, then I don't use it. Even if I can get a binary that was built for my compiler, maybe I'll want to switch compilers later and the library author will have disappeared, leaving me stuck.
That. Even with a library built exactly for the compiler I'm currently using, some optimization flag set to a different value is already enough to render the library unlinkable. Give me the source and don't make a fuss about it.

Luckily there's a lot of OpenSource libraries out there, and all the "I keep my precious code to myself" people are slowly dieing out. Code is overrated, especially the code of people who think it's precious.

[Edit] Of course sometimes you don't have a choice. And if you stick to C and C only for the interface, it will work. But that's not the topic. The topic was "export STL stuff", and that's only viable if you have the source code. Edited by Schrompf
0

Share this post


Link to post
Share on other sites
You have to do that anyway -- the C++ ABI (e.g. name mangling) isn't portable across compilers, so a library built by one compiler very likely just wont work with another compiler, no matter how simple/complex the interface is.

For a well defined API, this should never cause a problem. Now if you're going to start passing references to std::string / std::vector<> across your DLL boundary, then you're going to have issues. For a dll that defines a single C entry point (e.g. CreateMySDK()), then uses nothing but virtual interfaces (or infact, any C++ class that restricts communication to functions only, again making sure that the data types you pass into args are of a known size), then you should have no problem.

Every compiler includes some form of libtool to generate a link library for a DLL compiled with another compiler. It's not an impossible task....

That. Even with a library built exactly for the compiler I'm currently using, some optimization flag set to a different value is already enough to render the library unlinkable. Give me the source and don't make a fuss about it.
Which means you have been ignoring warning C4251 (i.e. you have a function arg, return type, or member var, in your DSO interface that is being statically linked in from another library. This is bad news!) . If you fix all of those warnings, the problems you describe will never happen. Edited by RobTheBloke
0

Share this post


Link to post
Share on other sites

[quote]The first solution that comes to my mind is to just re-write aspects of the STL that you want to use.[/quote]

 

The best solution is to stop passing STL containers across the DLL boundary. Ensure that you can only heap allocate your DLL objects (e.g. use a static create() method, rather than leaving the ctor as public). Finalize your classes with the DLL (private ctor / copy ctor). Make sure all member variables are private, and that all of your get/set methods have been DLL exported (also make sure you export the ctor/dtor/copy ctor).

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0