Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[package] boost/1.86.0: Linkage error for boost::fibers::context with MSVC on Windows #25888

Open
SidneyCogdill opened this issue Nov 9, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@SidneyCogdill
Copy link
Contributor

SidneyCogdill commented Nov 9, 2024

Description

on Windows with MSVC, boost fibers has linkage errors and can't be used properly.

MinGW doesn't have this issue. The prebuilt windows binaries (that works with MSVC) don't have this issue either.

main.cpp.obj : error LNK2019: unresolved external symbol "public: static class boost::fibers::context * __cdecl boost::fibers::context::active(void)" (?active@context@fibers@boost@@SAPEAV123@XZ) referenced in function "void __cdecl boost::this_fiber::yield(void)" (?yield@this_fiber@boost@@YAXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::fibers::context::yield(void)" (?yield@context@fibers@boost@@QEAAXXZ) referenced in function "void __cdecl boost::this_fiber::yield(void)" (?yield@this_fiber@boost@@YAXXZ)
hello_world_with_boost_context.exe : fatal error LNK1120: 2 unresolved externals

The issue is not that Boost can't be built by conan, or that linkage error occurs when building the Boost itself.

Package and Environment Details

  • Package Name/Version: boost/1.86.0
  • Operating System+version: Windows 11
  • Compiler+version: MSVC 17.11.35327.3
  • Conan version: conan 2.8.0
  • Python version: Python 3.11.9 (conan was installed from pipx, a different version of Python might be used inside of the isolated environment)

Conan profile

cmake-conan was used

Grabbed from CMake output:

[cmake] Profile host:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] build_type=Debug
[cmake] compiler=msvc
[cmake] compiler.runtime=dynamic
[cmake] compiler.runtime_type=Debug
[cmake] compiler.version=194
[cmake] os=Windows
[cmake] [conf]
[cmake] tools.build:compiler_executables={'c': 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/HostX64/x64/cl.exe', 'cpp': 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/HostX64/x64/cl.exe'}
[cmake] tools.cmake.cmaketoolchain:generator=Ninja
[cmake] 
[cmake] Profile build:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] build_type=Release
[cmake] compiler=gcc
[cmake] compiler.cppstd=gnu17
[cmake] compiler.libcxx=libstdc++11
[cmake] compiler.version=14
[cmake] os=Windows
[cmake] 

Steps to reproduce

https://github.com/conan-io/cmake-conan was used to automatically trigger conan when running CMake.

conanfile.py
# conanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain

class Recipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps"

    default_options = {
        "boost*:debug_level":1,
        "boost*:without_stacktrace":True,
    }

    def requirements(self):
        self.requires("boost/1.86.0")

    def generate(self):
        tc = CMakeToolchain(self, generator="Ninja")
        tc.user_presets_path = False
        tc.generate()
CMakeLists.txt
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)

# Point to the `conan_provider.cmake` from `cmake-conan`
list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES
     ${CMAKE_SOURCE_DIR}/cmake-conan/conan_provider.cmake)

project(hello_world_with_boost_context LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Boost REQUIRED)

add_executable(hello_world_with_boost_context main.cpp)

target_link_libraries(hello_world_with_boost_context PRIVATE boost::boost)
// main.cpp
#include <boost/fiber/all.hpp>

int main()
{
    boost::this_fiber::yield();
    return 0;
}

Logs

Click to expand log
[1/2 0.3/sec] Building CXX object CMakeFiles\hello_world_with_boost_context.dir\main.cpp.obj
[2/2 0.6/sec] Linking CXX executable hello_world_with_boost_context.exe
FAILED: hello_world_with_boost_context.exe 
C:\Windows\system32\cmd.exe /C "cd . && C:\Users\User\pipx\venvs\cmake\Lib\site-packages\cmake\data\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\hello_world_with_boost_context.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1441~1.341\bin\Hostx64\x64\link.exe /nologo CMakeFiles\hello_world_with_boost_context.dir\main.cpp.obj  /out:hello_world_with_boost_context.exe /implib:hello_world_with_boost_context.lib /pdb:hello_world_with_boost_context.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -LIBPATH:C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib   -LIBPATH:C:\Users\User\.conan2\p\b\bzip2879f985640c25\p\lib   -LIBPATH:C:\Users\User\.conan2\p\b\zlibe80175b9b9e96\p\lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_log_setup.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_unit_test_framework.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_type_erasure.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_log.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_locale.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_contract.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_wave.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_thread.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_test_exec_monitor.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_prg_exec_monitor.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_nowide.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_iostreams.lib  C:\Users\User\.conan2\p\b\bzip2879f985640c25\p\lib\bz2.lib  C:\Users\User\.conan2\p\b\zlibe80175b9b9e96\p\lib\zlib.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_graph.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_wserialization.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_url.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_random.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_tr1l.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_tr1f.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_tr1.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_c99l.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_c99f.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_c99.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_json.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_filesystem.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_coroutine.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_cobalt.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_chrono.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_timer.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_serialization.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_regex.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_program_options.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_exception.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_date_time.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_context.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_container.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_charconv.lib  C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_atomic.lib  bcrypt.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1441~1.341\bin\Hostx64\x64\link.exe /nologo CMakeFiles\hello_world_with_boost_context.dir\main.cpp.obj /out:hello_world_with_boost_context.exe /implib:hello_world_with_boost_context.lib /pdb:hello_world_with_boost_context.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console -LIBPATH:C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib -LIBPATH:C:\Users\User\.conan2\p\b\bzip2879f985640c25\p\lib -LIBPATH:C:\Users\User\.conan2\p\b\zlibe80175b9b9e96\p\lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_log_setup.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_unit_test_framework.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_type_erasure.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_log.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_locale.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_contract.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_wave.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_thread.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_test_exec_monitor.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_prg_exec_monitor.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_nowide.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_iostreams.lib C:\Users\User\.conan2\p\b\bzip2879f985640c25\p\lib\bz2.lib C:\Users\User\.conan2\p\b\zlibe80175b9b9e96\p\lib\zlib.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_graph.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_wserialization.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_url.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_random.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_tr1l.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_tr1f.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_tr1.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_c99l.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_c99f.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_math_c99.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_json.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_filesystem.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_coroutine.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_cobalt.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_chrono.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_timer.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_serialization.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_regex.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_program_options.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_exception.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_date_time.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_context.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_container.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_charconv.lib C:\Users\User\.conan2\p\b\boostf9d34849e3cee\p\lib\libboost_atomic.lib bcrypt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\hello_world_with_boost_context.dir/intermediate.manifest CMakeFiles\hello_world_with_boost_context.dir/manifest.res" failed (exit code 1120) with the following output:
main.cpp.obj : error LNK2019: unresolved external symbol "public: static class boost::fibers::context * __cdecl boost::fibers::context::active(void)" (?active@context@fibers@boost@@SAPEAV123@XZ) referenced in function "void __cdecl boost::this_fiber::yield(void)" (?yield@this_fiber@boost@@YAXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::fibers::context::yield(void)" (?yield@context@fibers@boost@@QEAAXXZ) referenced in function "void __cdecl boost::this_fiber::yield(void)" (?yield@this_fiber@boost@@YAXXZ)
hello_world_with_boost_context.exe : fatal error LNK1120: 2 unresolved externals
ninja: build stopped: subcommand failed.
09:13:00: The process "C:\Users\User\pipx\venvs\cmake\Lib\site-packages\cmake\data\bin\cmake.exe" exited with code 1.
Error while building/deploying project hello_world_with_boost_context (kit: Desktop Qt 6.8.0 MSVC2022 64bit)
When executing step "Build"
@SidneyCogdill SidneyCogdill added the bug Something isn't working label Nov 9, 2024
@Nekto89
Copy link
Contributor

Nekto89 commented Nov 9, 2024

Maybe it's caused by missing compiler.standard in your host profile?

@SidneyCogdill
Copy link
Contributor Author

SidneyCogdill commented Nov 9, 2024

Tried with compiler.cppstd=23, didn't work either. Doesn't even trigger a rebuild at all.

New profile
[cmake] ======== Input profiles ========
[cmake] Profile host:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] build_type=Debug
[cmake] compiler=msvc
[cmake] compiler.cppstd=23
[cmake] compiler.runtime=dynamic
[cmake] compiler.runtime_type=Debug
[cmake] compiler.version=194
[cmake] os=Windows
[cmake] [conf]
[cmake] tools.build:compiler_executables={'c': 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/HostX64/x64/cl.exe', 'cpp': 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/HostX64/x64/cl.exe', 'rc': 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.22621.0/x64/rc.exe'}
[cmake] tools.cmake.cmaketoolchain:generator=Ninja
[cmake] 
[cmake] Profile build:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] build_type=Release
[cmake] compiler=gcc
[cmake] compiler.cppstd=23
[cmake] compiler.libcxx=libstdc++11
[cmake] compiler.version=14
[cmake] os=Windows
[cmake] 
[cmake] 

I've also tried to make the build profile match the host profile by adding CONAN_BUILD_PROFILE="default;auto-cmake" (and it does for once, then it magically reverts back to gcc in subsequent CMake reconfiguration), nothing changes and nothing rebuilds.

@SidneyCogdill
Copy link
Contributor Author

SidneyCogdill commented Nov 9, 2024

# FIXME: Compilation errors on msvc shared build for boost.fiber https://github.com/boostorg/fiber/issues/314
if is_msvc(self):
self.options.without_fiber = True

Turns out when MSVC is detected, fiber is exempt from building. However, the issue that was mentioned has already been fixed upstream: boostorg/fiber#314

@uilianries
Copy link
Member

@SidneyCogdill THank you for detailing the case. The hotfix is not included yet in Boost release, is mapped to 1.87.0.

Still, I'll update the validation to consider build_compiler only and validate it locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants