gpt4 book ai didi

c++ - 构建 cpp-netlib 共享库

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:22:06 25 4
gpt4 key购买 nike

我正在尝试使用 boost 和 cpp-netlib。 cpp-netlib 的静态库大约是40m(发行版),即使链接到一个小的helloworld 也可能非常。所以我想在开发时尝试动态dll+ import lib,如何为cpp-netlib构建dll+lib?

我尝试修改 CMakeLists.txt,将 SHARED 添加到行中

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})

但只生成.dll,没有生成.lib。谷歌说必须有导出功能。那么一种方法可能是编写一些虚拟函数并将它们导出以生成 .lib?还有其他办法吗?

最佳答案

在当前的 cpp-netlib 版本 0.12.0 之前是不可能的。仅当(且仅当)使用 __declspec(dllexport) 属性或 DEF 文件导出一个或多个函数时,链接器才会为 DLL 生成导入库。但是,这是库代码中当前未实现的功能。这就是为什么在构建之后您只能看到 DLL,而看不到它们各自的导入库。

本款official documentation确认只生成静态库:

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.

如果你想大幅减少构建时间,我建议你到precompile您在代码中包含的库 header 。

关于c++ - 构建 cpp-netlib 共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24576689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com