nigels-com / glew

The OpenGL Extension Wrangler Library
Other
2.62k stars 614 forks source link

Visual Studio: warning LNK4098 error when link the program #100

Open ghost opened 8 years ago

ghost commented 8 years ago

When I build program in x64 debug mode, the output console shows "warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs", when I build the same program in x64 release mode, no warning shows. So how to solve this problem ?

nigels-com commented 8 years ago

Are you using the pre-built Windows binaries? The bundled Visual Studio projects? cmake? Do you see this warning for glewinfo and visualinfo?

nigels-com commented 7 years ago

Need more information on this one.

gris-martin commented 2 years ago

I realize this is old, but I've had a very similar issue (but with LIBCMT instead of MSVCRT), and did some digging.

If I've understood things correctly, the warning comes when an application is built with one version of the C runtime library (CRT), and a dependent library was built with support for another. Looking at the vcxproj files, GLEW specifies the "MultiThreaded" version (/MT) for release libraries builds, which gives a dependency on libcmt.lib, and the "MultiThreadedDebugDLL" version (/MDd) for debug builds, which gives a dependency on msvcrtd.lib (and a corresponding dll).

If your application then links with e.g. glew32_s.lib, built in release, while it has the /MTd flag set (corresponding to "MultiThreadedDebug"), it will link with both libcmt.lib (because of glew32_s.lib), and with libcmtd.lib (because of the flag in your build). If you don't want the warnings, there are 3 possible ways to solve this:

  1. Use the same flag in your application as the one GLEW was built with.
  2. Rebuild GLEW to use the same flag as your application.
  3. Add the /NODEFAULTLIB:xxx linker option (specified in Properties -> Linker -> Command Line -> Additional Options), where xxx is the name of the library you want to ignore (most likely libcmt.lib, since that is what GLEW release uses by default). This seems a bit hacky too me, but it seems to be what Microsoft recommends: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4098

I would prefer option 2, but it seems that GLEW is tricky to build (or at least to generate the needed code for) on Windows.

Another option could be to supply more binaries in the releases:

Some resources: