What's the correct way to handle dllexport/dllimport in Meson? #15018
-
When building a cross-platform library that can be either static or shared, libraries usually prefix all function declarations with a special macro (e.g. "MY_EXPORT") that in case of Windows is defined like so: #ifdef MY_SHARED
# ifdef MY_BUILDING_ITSELF
# define MY_EXPORT __declspec(dllexport)
# else
# define MY_EXPORT __declspec(dllimport)
# endif
#else
# define MY_EXPORT
#endif The The only missing part here is how to define the Even though on the library side this can be done with What is the correct way to approach this? Am I missing something about how Meson handles static/shared libraries? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
usually you'd pass the arguments as separate arrays, one passed to the library() function (to indicate BUILDING_ITSELF / dllexport) and a different one passed to the declare_dependency() function (indicating dllimport). The "building as shared" macro should be passed to c_shared_args, and also to declare_dependency since a declared dependency always links shared if it can (unless you use get_static_lib on a both_libraries() object to explicitly request the static version). |
Beta Was this translation helpful? Give feedback.
-
I was confused about how DLL compilation works. Turns out, So, the optimal header code is: #ifdef MY_SHARED
# define MY_EXPORT __declspec(dllexport)
#else
# define MY_EXPORT
#endif and doing |
Beta Was this translation helpful? Give feedback.
That's why you will want to check like: