Skip to content

Failed to build mcpp project with glfw dependency #539

Closed

Description

@SnowFoxqwq

The problem i've met

I'm building my mcpp project with glfw library, and this is my mcpp.toml file content:

[package]
name        = "mcpp_tut"
version     = "0.1.0"
description = "A modular C++23 package"
license     = "Apache-2.0"

[dependencies.compat]
"glfw" = "3.4"

However, when i built my mcpp project, something wrong while building the project, and here is the log:

 mcpp build
   Resolving toolchain
    Resolved llvm@20.1.7 → @mcpp/registry/data/xpkgs/xim-x-llvm/20.1.7/bin/clang++.exe
    Resolved sysroot msvc@system → MSVC 14.50.35717 (system: Visual Studio Community 2026) · Windows SDK 10.0.26100.0
      Target x86_64-pc-windows-msvc
    Inferred sources [src/**/*.{cppm,cpp,cc,c,S,s,asm}]
    Inferred target mcpp_tut (bin from src/main.cpp)
   Compiling compat.khrplatform v2026.05.31
   Compiling compat.opengl v2026.05.31
   Compiling compat.glfw v3.4
   Compiling mcpp_tut v0.1.0 (.)
error: build failed in mcpp_tut v0.1.0 (.)
failed: bin/mcpp_tut.exe
C:/Users/28900/.mcpp/registry/data/xpkgs/xim-x-llvm/20.1.7/bin/clang++.exe @bin/mcpp_tut.exe.rsp -o bin/mcpp_tut.exe -fms-runtime-lib=dll -fuse-ld=lld -Xmicrosoft-visualc-tools-root "C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717" -Xmicrosoft-windows-sdk-root "C:\Program Files (x86)\Windows Kits\10" -Xmicrosoft-windows-sdk-version 10.0.26100.0 -fms-compatibility-version=19.50.35723 -lgdi32
lld-link: error: undefined symbol: __declspec(dllimport) LoadCursorW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1290
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:232
>>>               obj/compat_glfw/src/win32_window.o:(updateCursorImage)
lld-link: error: undefined symbol: __declspec(dllimport) LoadImageW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1297
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1303
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2341
>>>               obj/compat_glfw/src/win32_window.o:(_glfwCreateStandardCursorWin32)
lld-link: error: undefined symbol: __declspec(dllimport) RegisterClassExW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1308
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_init.c:381
>>>               obj/compat_glfw/src/win32_init.o:(createHelperWindow)
lld-link: error: undefined symbol: __declspec(dllimport) GetSystemMetrics
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1317
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1324
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1325
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced 11 more times
lld-link: error: undefined symbol: __declspec(dllimport) GetMonitorInfoW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1348
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1470
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:431
>>>               obj/compat_glfw/src/win32_window.o:(fitToMonitor)
>>> referenced 5 more times
lld-link: error: undefined symbol: __declspec(dllimport) AdjustWindowRectEx
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1366
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1453
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1655
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowPosWin32)
>>> referenced 8 more times
lld-link: error: undefined symbol: __declspec(dllimport) CreateWindowExW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1387
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_init.c:389
>>>               obj/compat_glfw/src/win32_init.o:(createHelperWindow)
lld-link: error: undefined symbol: __declspec(dllimport) SetPropW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1407
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
lld-link: error: undefined symbol: __declspec(dllimport) MonitorFromWindow
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1427
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1779
>>>               obj/compat_glfw/src/win32_window.o:(_glfwGetWindowContentScaleWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:489
>>>               obj/compat_glfw/src/win32_window.o:(maximizeWindowManually)
>>> referenced 1 more times
lld-link: error: undefined symbol: __declspec(dllimport) GetWindowPlacement
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1455
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
lld-link: error: undefined symbol: __declspec(dllimport) OffsetRect
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1456
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:512
>>>               obj/compat_glfw/src/win32_window.o:(maximizeWindowManually)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:517
>>>               obj/compat_glfw/src/win32_window.o:(maximizeWindowManually)
lld-link: error: undefined symbol: __declspec(dllimport) SetWindowPlacement
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1462
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
lld-link: error: undefined symbol: __declspec(dllimport) SetWindowPos
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1472
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:432
>>>               obj/compat_glfw/src/win32_window.o:(fitToMonitor)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1659
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowPosWin32)
>>> referenced 8 more times
lld-link: error: undefined symbol: __declspec(dllimport) DragAcceptFiles
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1481
>>>               obj/compat_glfw/src/win32_window.o:(createNativeWindow)
lld-link: error: undefined symbol: __declspec(dllimport) GetWindowLongW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2024
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowMousePassthroughWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:500
>>>               obj/compat_glfw/src/win32_window.o:(maximizeWindowManually)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:506
>>>               obj/compat_glfw/src/win32_window.o:(maximizeWindowManually)
>>> referenced 5 more times
lld-link: error: undefined symbol: __declspec(dllimport) GetLayeredWindowAttributes
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2027
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowMousePassthroughWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2054
>>>               obj/compat_glfw/src/win32_window.o:(_glfwGetWindowOpacityWin32)
lld-link: error: undefined symbol: __declspec(dllimport) SetWindowLongW
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2043
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowMousePassthroughWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:502
>>>               obj/compat_glfw/src/win32_window.o:(maximizeWindowManually)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1896
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowMonitorWin32)
>>> referenced 4 more times
lld-link: error: undefined symbol: __declspec(dllimport) SetLayeredWindowAttributes
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2046
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowMousePassthroughWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2072
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowOpacityWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:2076
>>>               obj/compat_glfw/src/win32_window.o:(_glfwSetWindowOpacityWin32)
lld-link: error: undefined symbol: __declspec(dllimport) ShowWindow
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1820
>>>               obj/compat_glfw/src/win32_window.o:(_glfwShowWindowWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1786
>>>               obj/compat_glfw/src/win32_window.o:(_glfwIconifyWindowWin32)
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1791
>>>               obj/compat_glfw/src/win32_window.o:(_glfwRestoreWindowWin32)
>>> referenced 3 more times
lld-link: error: undefined symbol: __declspec(dllimport) BringWindowToTop
>>> referenced by C:\Users\28900\.mcpp\xpkgs\compat-x-glfw\3.4\src\win32_window.c:1835
>>>               obj/compat_glfw/src/win32_window.o:(_glfwFocusWindowWin32)
lld-link: error: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

It seems that the compiler forgot to link some basic libraries like user32, "shell32" etc.

The solution

i added some command to link the libraries, and the final cpp.toml is like that:

[package]
name        = "mcpp_tut"
version     = "0.1.0"
description = "A modular C++23 package"
license     = "Apache-2.0"

[dependencies.compat]
"glfw" = "3.4"

[build]
ldflags = ["-luser32", "-lshell32", "-ldwmapi", "-lopengl32", "-lgdi32"]

i am not sure that whether the libraries above are the minimum requirement to build glfw.

Hope mcpp-index can fix this issue and link the libraries automatically while building glfw library.

Activity

  1. Sunrisepeak commented on Oct 17, 2026

    @Sunrisepeak
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions