c++boostcmakedynamic-linkingcpp-netlib

build cpp-netlib shared library


I'm trying to use boost and cpp-netlib. The static library of cpp-netlib is about 40m(release version), even linking to a small helloworld could be very slow. So I'd like to try dynamic dll+ import lib when developing, how can I build dll+lib for cpp-netlib?

I tried modify the CMakeLists.txt, add SHARED to the lines

add_library(cppnetlib-uri SHARED ${CPP-NETLIB_URI_SRCS})
add_library(cppnetlib-server-parsers SHARED ${CPP-NETLIB_HTTP_SERVER_SRCS})
add_library(cppnetlib-client-connections SHARED ${CPP-NETLIB_HTTP_CLIENT_SRCS})

but only .dll are generated, there's no .lib. Google says there must be export functions. So one way could be writing some dummy function and export them to generate the .lib? Any other way?


Solution

  • It is not possible up to the current version 0.12.0 of cpp-netlib. The linker will only generate an import library for a DLL if (and only if) one or more functions are exported either using the __declspec(dllexport) attribute or a DEF file. However, this is a feature currently not implemented in the code of the library. That is why after the build you can just see the DLLs, but not their respective import libraries.

    This section of the official documentation confirms that only static libraries are meant to be generated:

    As of version 0.9.3, cpp-netlib produces three static libraries. Using Visual C++ on Windows they are:

    cppnetlib-client-connections.lib
    cppnetlib-server-parsers.lib
    cppnetlib-uri.lib

    Users can find them in ~/cpp-netlib-build/libs/network/src.

    If you want to substantially reduce the build time, I suggest you to precompile the library's headers that you include in your code.