Skip to main content
removed fluff and made title more specific
Source Link
JaMiT
  • 18.6k
  • 5
  • 20
  • 44

Linking errors Unresolved external symbol after switching from MinGW+GCC to MSVC

Hey all—hoping a fresh set of eyes can spot what I’m doing wrong. I’m porting my small C++ game-engine project (followed along with The Cherno’s series) 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.)

Sorry if my formatting incorrect, This is my first post on here and I don't often ask for help on the internet. Any help is greatly appreciated!

And here's a linkLink to the GithubGitHub repo if anyones interested: https://github.com/treybertram06/Honey

As someone mentioned, I forgot to add howHow 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.

Linking errors after switching from MinGW+GCC to MSVC

Hey all—hoping a fresh set of eyes can spot what I’m doing wrong. I’m porting my small C++ game-engine project (followed along with The Cherno’s series) 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.)

Sorry if my formatting incorrect, This is my first post on here and I don't often ask for help on the internet. Any help is greatly appreciated!

And here's a link to the Github repo if anyones interested: https://github.com/treybertram06/Honey

As someone mentioned, I forgot to add 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.

Unresolved external symbol after switching from MinGW+GCC to MSVC

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.

more relevant tags
Link
Aleksandr Medvedev
  • 10.3k
  • 3
  • 25
  • 66
added 745 characters in body
Source Link

Hey all—hoping a fresh set of eyes can spot what I’m doing wrong. I’m porting my small C++ game-engine project (followed along with The Cherno’s series) 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.)

Sorry if my formatting incorrect, This is my first post on here and I don't often ask for help on the internet. Any help is greatly appreciated!

And here's a link to the Github repo if anyones interested: https://github.com/treybertram06/Honey

As someone mentioned, I forgot to add 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.

Hey all—hoping a fresh set of eyes can spot what I’m doing wrong. I’m porting my small C++ game-engine project (followed along with The Cherno’s series) 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.)

Sorry if my formatting incorrect, This is my first post on here and I don't often ask for help on the internet. Any help is greatly appreciated!

And here's a link to the Github repo if anyones interested: https://github.com/treybertram06/Honey

Hey all—hoping a fresh set of eyes can spot what I’m doing wrong. I’m porting my small C++ game-engine project (followed along with The Cherno’s series) 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.)

Sorry if my formatting incorrect, This is my first post on here and I don't often ask for help on the internet. Any help is greatly appreciated!

And here's a link to the Github repo if anyones interested: https://github.com/treybertram06/Honey

As someone mentioned, I forgot to add 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.

Source Link
Loading