Dlib: How do I compile dlib into .dll file?

Created on 4 Jul 2018  路  9Comments  路  Source: davisking/dlib

From building dlib using cmake, I found a .lib file here:
dlib-19.13\build\dlib\Release\dlib19.13.0_release_32bit_msvc1900.lib"

But I want .dll file. So I thought that maybe I could use dlib-19.13\build\dlib\dlib.sln that was generated using cmake to generate .dll file. But I couldn't find an option to change the Applications Settings to be DLL inside Visual Studio 2017. As far as I know, it's only possible to create a DLL app from the start but not possible to change later.

So how do I compile all functionalities of dlib commands into .dll file? I want to use it inside Unity3D game engine.

If all the previous explanations are confusing for you, please ignore it and tell me how to compile dlib as a .dll library. If it's too difficult or impossible to compile all functionalities then please show me how to export just one functionality like shape_predictor class to predict facial landmark. It will be used with other languages like C# or Python.

Any better approach is appreciated. Thank you.

Most helpful comment

Just put it in anyway. ALL CMake projects can use that flag. It's an inbuilt CMake feature.

All 9 comments

dlib-19.13/build $ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -G"Visual Studio 15 2017 Win64" ..

The magic here is 'BUILD_SHARED_LIBS', which tells CMake to generate a dll instead.

Thanks! This is native C library, right?
If so how do I know which functions are included in this DLL? As we need to create a function prototype file for it. How do I use this DLL file?
I ran the command you suggested without -G option and then I ran cmake --build . --config Release
I found dlib19.13.0_release_32bit_msvc1914.dll in my build/dlib/Release.

I saw that the DLL file is quite small compared to LIB file in the previous build. It is 390 KB while LIB file is 13.7 MB.
Is this expected?

Yes, this is the expected results. DLL will be smaller. However, static lib will likely be smaller again at link time as it strips out anything you don't use. Meanwhile the DLL sizes are fixed.

Just use the header files included in this project to call the functions if you are linking to the DLL. You will have different functions depending on what defines you set (i.e. Using cuda, sqlite, etc).

Warning: this issue has been inactive for 20 days and will be automatically closed on 2018-09-23 if there is no further activity.

If you are waiting for a response but haven't received one it's likely your question is somehow inappropriate. E.g. you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's documentation, or a Google search.

Sorry for reopening this but Dlib 19.19 doesn't have any BUILD_SHARED_LIBS flags in Cmake. How can we build dlib as a Dynamic library and not a Static library?

Thanks

That's a CMake flag. You just set it and everything should respect it.

Unfortunately, It's not present (or shown) in CMake-GUI.

image

image

Just put it in anyway. ALL CMake projects can use that flag. It's an inbuilt CMake feature.

Thanks, BUT is it possible to add this flag using the GUI? or one should just use the Command Line?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lvella picture lvella  路  4Comments

pliablepixels picture pliablepixels  路  4Comments

alison-carrera-pegasus picture alison-carrera-pegasus  路  3Comments

vijaysagi picture vijaysagi  路  5Comments

AeroClassics picture AeroClassics  路  4Comments