Advertisement

Should i to compile using static library or shared library?

Started by October 12, 2014 01:33 PM
3 comments, last by TalissonBento 10 years, 3 months ago

Hello everyone, i've been reading some articles about how to compile projects and with it came the question on my mind about shared library and static.

What's better way to compile my game?
What become it fastest?
Advantage and disadvantage to use it?

Sorry about my english, but this forum is the better know and is helping me so much. smile.pngtongue.png

Please this question must be answered for Linux, Windows and Mac.

I recently came upon this problem in Windows where there were two shared libraries compiling with Lua statically, which caused a crash when passing a lua_State* between the two. It was fixed by linking Lua as a shared library, which is a wonderfully descriptive name for when it is appropriate to use, seeing as it was shared by the two libraries.

It will differ per project, and most libraries will say when they are better done as static libraries. If you want some definitive answer, then link everything shared until the library explicitly says to do it static.

In the case of choosing static or shared, the difference in code execution speed will not be great enough to make a difference. There are some link-time optimizations that can happen with static libraries, but I wouldn't count on that bringing you from 30fps to 60fps.

Advertisement

There's no big performance difference either way.

I prefer to just compile everything as static, and link them into my game's EXE because I personally find it to be a lot simpler, especially on Windows where DLLs require you to manually mark everything as being DLL-exported/imported/etc...

Shared libraries introduce potential for mistakes, due to rules about memory management and library versioning. Converting static libraries to shared can lead to huge headaches. My preference is to set things up entirely as static unless I have a specific reason to want a shared library. I rarely do.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

I'am glad about to answers. thank you so much guys!

This topic is closed to new replies.

Advertisement