fiber
fiber copied to clipboard
Could not link fiber 1.84.0 as shared library on Windows 10
Hello! We are trying to package the Boost 1.84.0 on Conan but we are facing a linkage error related to the new boost::fibers::make_stack_allocator_wrapper
introduced on 1.84.0
We have the follow error when trying to link to the fiber example work_sharing.cpp:
boost/1.84.0 (test package): RUN: cmake --build "C:\Users\uilia\Development\conan\conan-center-index\recipes\boost\all\test_package\build\msvc-193-x86_64-17-release" --config Release
MSBuild version 17.3.1+2badb37d1 for .NET Framework
1>Checking Build System
Building Custom Rule C:/Users/uilia/Development/conan/conan-center-index/recipes/boost/all/test_package/CMakeLists.txt
fiber.cpp
C:/Users/uilia/.conan2/p/b/boost9b0969d51319d/p/include\boost/fiber/stack_allocator_wrapper.hpp(85,43): error C2491: 'boost::fibers::make_stack_allocator_wrapper': definition of dllimport function not allowed [C:\Users\uilia\Development\conan\conan-center-index\recipes\boost\all\test_package\build\msvc-193-x86_64-17
-release\fiber_exe.vcxproj]
Building Custom Rule C:/Users/uilia/Development/conan/conan-center-index/recipes/boost/all/test_package/CMakeLists.txt
In summary, we using the exactly same configuration for Boost 1.83.0 and it works perfectly with the same example file in this repository.
All build and test logs are available on https://c3i.jfrog.io/c3i/misc/summary.html?json=https://c3i.jfrog.io/c3i/misc/logs/pr/21747/11-windows-visual_studio/boost/1.84.0//summary.json
We use b2 to build Boost, including fiber. The CMake is only when consuming Boost, so we are not trying unofficial support.
Some extra information about the generated fiber.dll:
Environment
Boost version: 1.84.0 OS: Windows 10 Compiler: MSVC 193 Build Type: Release Runtime: Dynamic (MD)
Steps to reproduce
git clone -b boost-1.84.0 https://github.com/toge/conan-center-index.git
cd recipes/boost/all
conan create . --version=1.84.0
OR, just build Boost as usual and try to link to work_sharing.cpp.
I got this compile error too, then if I change line of code stack_allocator_wrapper.hpp:85
BOOST_FIBERS_DECL stack_allocator_wrapper make_stack_allocator_wrapper(Args && ... args)
to
stack_allocator_wrapper make_stack_allocator_wrapper(Args && ... args)
I could compile it successfully.
It seems that BOOST_FIBERS_DECL
is expanded as __declspec(dllimport)
when used as shared library, but MSVC wouldn't allow dllimport
on definition of a function. see here
'identifier' : definition of dllimport function not allowed Data, static data members, and functions can be declared as dllimports but not defined as dllimports. To fix this issue, remove the __declspec(dllimport) specifier from the definition of the function.
I found that the following code will compile:
#define BOOST_FIBERS_STATIC_LINK
#include <boost/fiber/all.hpp>
and in your cmake link Boost::context and Boost::fiber
@xiaodaxia-2008 Thank you for sharing your solution! 😄
you are welcome! 😊