1

So this is a common error but all the posts say I need to pay more attention to which versions of libraries I'm including. I'm using SDL2, OpenGL, and SDL_Mixer... I don't have any options in what I include except to stick with 32-bit libs.

Debug compiles fine but release gives me the LNK2005 error unless I set runtime libraries to /MD. I'd like to avoid that extra dependency. The resulting executable stops responding on SDL initializations or some OpenGL calls unless Visual Studio launches the release build. So I've got some kind of multi-threading issue but I'm not close to understanding it. Little help?

UPDATE: /FORCE:MULTIPLE allows the project to be compiled with /MT. But just like with /MD, the resulting executable crashes unless visual studio launches the release build. What does that mean?

UPDATE2: Use /MD in SDL projects. Crash was just a memory error the debugger wasn't catching. Linking was unrelated.

spinning
  • 119
  • 1
  • 1
  • 10
  • have you tried ignoring libcmt.lib in your linker options? – ryrich Mar 22 '14 at 07:09
  • Oh right, ignoring libcmt.lib produces 50 LNK2001 and LNK1120 unresolved external symbols and externals. – spinning Mar 22 '14 at 07:22
  • This is not possible, having multiple copies of the CRT in a process never ends well. Just SDL_Mixer already has eight DLLs, trying to eliminate msvcrxx.dll to remove *one* dependency is utterly pointless. Remove the dependency on the SDL DLLs first. And good luck with that. – Hans Passant Mar 22 '14 at 08:12
  • I don't understand, how can I remove the dependency on SDL DLL? Games ship with the DLLs. – spinning Mar 22 '14 at 08:31
  • They do, like msvcrxx.dll. You are trying to eliminate the dependency that's "easy", just change a compiler setting. It will not work, you have to do the hard ones first. Starting at SDL. – Hans Passant Mar 22 '14 at 09:29

2 Answers2

1

Ok, so your only other options I see are

(1) ignoring the other library that is causing the LNK2005 error (since you are defining something in two places, it doesn't know which one to use. Since ignoring libcmt.lib caused a lot of issues, maybe try the other place that defines the method).

2) Use /FORCE:MULTIPLE in your linker command line options, which will have it allow multiple definitions of a symbol.

ryrich
  • 2,164
  • 16
  • 24
  • Ignored msvcrt.lib instead and only had one unresolved error for fprintf. I am including stdio.h, how can I fix that? – spinning Mar 22 '14 at 07:46
1

Is rebuilding SDL an option? If so

  • get the source from libsdl.org
  • go to the VisualC directory
  • select the relevant solution
  • from there, for each of the projects, change the build type from /MD to /MT
  • rebuild: you should now just get a lib and DLL which are built as /MT and should link with your program compiled as /MT. You should no longer have to resort to /ignorelibs and /forcemultiple
cup
  • 7,589
  • 4
  • 19
  • 42