Skip to content

Common pattern for exporting symbols from shared library for msvc and gcc #10822

Answered by eli-schwartz
CorrodedCoder asked this question in Q&A
Discussion options

You must be logged in to vote

There are two ways to do this in MSVC, and two ways to do this in GCC.

GCC has version scripts and MSVC has def files. They use different formats, sadly, and involve passing external files to the linker.

GCC also has symbol visibility and MSVC has the dllexport declspec. You can stick this inside a header as a macro and choose the correct one per platform, with the caveat that MSVC is dumb and actually requires you to use different values depending on whether you are building a static or shared library -- and have some extra pain if you want to build both, you have to compile all source files twice in that case.

Your example shows using the first method. The problem is that you always nee…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@CorrodedCoder
Comment options

@eli-schwartz
Comment options

@CorrodedCoder
Comment options

@CorrodedCoder
Comment options

@CorrodedCoder
Comment options

Answer selected by CorrodedCoder
Comment options

You must be logged in to vote
1 reply
@CorrodedCoder
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants