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.
opengl_contextbut the symbol name isOpenGLContext. Casing and underscores matter. This mismatch could lead to a false negative.dllimport/dllexportis required for msvc for dynamic library...