1

I’m porting my small C++ project from MinGW + GCC to MSVC 2022 with the Ninja generator. On MinGW everything links fine, but with MSVC I keep getting this:

engine.lib(windows_window.cpp.obj) : error LNK2019:
unresolved external symbol
Honey::OpenGLContext::OpenGLContext(GLFWwindow*)
referenced in Honey::WindowsWindow::init(...)
fatal error LNK1120: 1 unresolved externals

engine is a static lib; opengl_context.cpp is in its source list.

application links: engine glfw glm glad imgui.

Tried duplicate-link trick and /WHOLEARCHIVE:engine.lib → same error.

lib.exe /LIST engine.lib | findstr opengl_context shows nothing (object never archived).

Clean rebuild shows no compile errors for that file.

Why would MSVC skip archiving a compiled .obj while MinGW includes it? Any CMake/MSVC static-lib gotchas I’m missing?

(Happy to share full CMakeLists or logs.)

Link to the GitHub repo: https://github.com/treybertram06/Honey

How I'm linking the library:

add_executable(application src/application.cpp)

# first pass
target_link_libraries(application PRIVATE
    engine               # ← static lib that contains all engine .cpp’s
    glfw glm glad imgui  # external deps
)

# second pass try to make MSVC rescan
target_link_libraries(application PUBLIC engine)

# I’ve also tried, instead of the second scan
target_link_options(application PRIVATE "/WHOLEARCHIVE:engine.lib")

But, opengl_context.cpp.obj never appears in engine.lib (confirmed with lib.exe /LIST engine.lib | findstr opengl_context making no output), so MSVC can’t resolve Honey::OpenGLContext::OpenGLContext.

5
  • 1
    You are talking about linking errors, but you don't provide debugging details on how you link the libraries. Commented May 9 at 6:53
  • On an unrelated note, the name MinGW is an abbreviation of Minimalist GNU for Windows. Here GNU implies GCC, so "MinGW + GCC" is like saying "GCC + GCC" which makes no sense. Commented May 9 at 7:12
  • 1
    As for your problem, you search for opengl_context but the symbol name is OpenGLContext. Casing and underscores matter. This mismatch could lead to a false negative. Commented May 9 at 7:14
  • 2
    On github repo, you have CMake which uses static lib for engine, and premake which uses dynamic lib, dllimport/dllexport is required for msvc for dynamic library... Commented May 9 at 7:44
  • Generate a export header for your library and include it when packaging your library. Commented May 9 at 10:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.