简体   繁体   English

如何将boost库链接为动态库而不是vcpkg中的static

[英]How to link boost library as dynamic library instead of static in vcpkg

I'm using VS 2019 with vcpkg and boost 1.81我正在使用带有 vcpkg 和 boost 1.81 的 VS 2019

I've created a Dynamic Link Library Project (c++) and I've added the boost serialization library headers.我创建了一个动态链接库项目 (c++) 并添加了 boost 序列化库标头。

when I set vcpkg to use static libraries it builds fine, however if i set the "Use static Libraries" to No then I get the following compiler errors当我将 vcpkg 设置为使用 static 库时,它构建良好,但是如果我将“使用 static 库”设置为否,则会出现以下编译器错误

Severity    Code    Description Project File    Line    Suppression State
Error   C2491   'boost::archive::detail::archive_serializer_map<Archive>::insert': definition of dllimport function not allowed C:\dev\vcpkg\installed\x86-windows\include\boost\archive\impl\archive_serializer_map.ipp    41  
Error   C2491   'boost::archive::detail::archive_serializer_map<Archive>::erase': definition of dllimport function not allowed  C:\dev\vcpkg\installed\x86-windows\include\boost\archive\impl\archive_serializer_map.ipp    49  
Error   C2491   'boost::archive::basic_binary_iprimitive<Archive,Elem,Tr>::basic_binary_iprimitive': definition of dllimport function not allowed   C:\dev\vcpkg\installed\x86-windows\include\boost\archive\impl\basic_binary_iprimitive.ipp   146 
Error   C2491   'boost::archive::basic_binary_iprimitive<Archive,Elem,Tr>::~basic_binary_iprimitive': definition of dllimport function not allowed  C:\dev\vcpkg\installed\x86-windows\include\boost\archive\impl\basic_binary_iprimitive.ipp   170 
Error   C2491   'boost::archive::detail::archive_serializer_map<Archive>::insert': definition of dllimport function not allowed C:\dev\vcpkg\installed\x86-windows\include\boost\archive\impl\archive_serializer_map.ipp    41  
Error   C2491   'boost::archive::detail::archive_serializer_map<Archive>::erase': definition of dllimport function not allowed  C:\dev\vcpkg\installed\x86-windows\include\boost\archive\impl\archive_serializer_map.ipp    49  
...[redacted]

what should i do to get it to build as a dynamic library?我应该怎么做才能将其构建为动态库?

UPDATE 2023/1/30 this issue happens only when adding the portable_binary_iarchive and portable_binary_iarchive files to the project.更新 2023/1/30 此问题仅在将portable_binary_iarchiveportable_binary_iarchive文件添加到项目时发生。 these files are not part of the standard boost library, however they are included in the examples.这些文件不是标准 boost 库的一部分,但它们包含在示例中。

you can create a CMake project, add the following commond in your CMakeLists.txt :您可以创建一个 CMake 项目,在您的CMakeLists.txt中添加以下内容:

set(Boost_USE_STATIC_LIBS OFF)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM