Skip to content

Make correct use of `declspec(dllimport)`/`declspec(dllexport)`

hrxi requested to merge hrxi/vala:pr_dllimport into main

When building a library, all exported symbols must carry declspec(dllexport), but when using the library's header files from elsewhere, declspec(dllimport)` must be used. In order to achieve that, the header file must be aware of whether it's being used to build or user the library.

The curl library solves this by defining a BUILDING_LIBCURL preprocessor directive. We do a similar thing and define VALA_BUILDING_{library} instead.

Each source and header file now defines VALA_EXTERN appropriately at the beginning, and undefines it at the end. This means definitions from different files do not clash.

For functions, the previous method of always declaring all symbols declspec(dllexport) works, but comes with a performance penalty of a trampoline function. For global variables, however, the previous method would result in a linker error. See also https://web.archive.org/web/20140808231508/http://blogs.msdn.com/b/russellk/archive/2005/03/20/399465.aspx.

This fixes #1477.

Merge request reports