Shared by default
aschrein opened this issue · comments
Line 213 in da0a9c6
I think it creates a shared library by default on Windows 10/MSVS 2019. Adding STATIC explicitly made it static for me. Not sure if that's consistent behaviour.
Hi @aschrein,
Thank you for alerting me to this. I tried to reproduce using Microsoft Visual Studio Community 2019 Version 16.4.5
, and I cannot.
In CMakeCache.txt
, I have MARL_BUILD_SHARED:BOOL=False
. BUILD_SHARED_LIBS
is undefined.
I cleaned the output directories, and rebuilt:
c:\src\marl\out\build\x64-Release>dir marl.*
Volume in drive C is Windows
Volume Serial Number is BA92-FD6B
Directory of c:\src\marl\out\build\x64-Release
15/06/2020 10:18 AM 3,877,600 marl.lib
Setting MARL_BUILD_SHARED:BOOL=True
, will attempt to build marl as a dll, but you may notice that with a clean build, the tests, benchmarks and samples fail to link. This is because we're not currently exporting any public dll symbols, and the marl.lib
import library is not being produced (presumably because it is empty) which is needed to link the applications.
Looking a CMake's documentation:
add_library
STATIC
,SHARED
, orMODULE
may be given to specify the type of library to be created.STATIC
libraries are archives of object files for use when linking other targets.SHARED
libraries are linked dynamically and loaded at runtime.MODULE
libraries are plugins that are not linked into other targets but may be loaded dynamically at runtime usingdlopen
-like functionality. If no type is given explicitly the type isSTATIC
orSHARED
based on whether the current value of the variableBUILD_SHARED_LIBS
is ON.
BUILD_SHARED_LIBS
Global flag to cause
add_library()
to create shared libraries if on.If present and true, this will cause all libraries to be built shared unless the library was explicitly added as a static library. This variable is often added to projects as an
option()
so that each user of a project can decide if they want to build the project using shared or static libraries
(bold emphasis mine)
So the docs also suggest that we shouldn't be getting dlls built by default, unless you're using BUILD_SHARED_LIBS
.
This did highlight to me that attempting to use MARL_BUILD_SHARED
/ BUILD_SHARED_LIBS
on Windows will fail miserably, so I've created #152 to actually export the dll symbols, allowing use of marl as a dll.
If at all possible, can you confirm that you are indeed statically building without #152? If you're somehow building and linking marl as a dll, I'd like to figure out why and how :)
Thanks for your answer.
I can't verify right now but I guess you're correct that something was wrong rather on my side. I'll let you know once I have a chance whether it was BUILD_SHARED_LIBS or not.
#152 has landed. If you still have issues building DLLs, please comment on here and I'll reopen.
Cheers!