Box2D library causes errors

One side note, you may want to name your .lib something other than engine.lib, maybe something more descriptive or specific like Box2D.lib. Also, it may be a good idea to include the compiled .lib in the SVN download, so that people don't have to compile it every time.

Anyway, I've been trying to get my program to work and it seems that in Release mode, when I add the Box2d.lib (I renamed it) library to my include list, I get a bunch of errors like these:

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)

What's the deal?
I'll think about your naming suggestion and providing binaries. I'd rather not get into DLLs.

The error you are seeing is because the engine library is being built with static linkage against the release multi-threaded C runtime library. However, you are trying to build a with static linkage against the debug C runtime library. To fix this I suggest linking with the debug version of the Box2d engine library.

I decided to use static (not dynamic) C runtime linkage so that demos can be produced that will run on anyone's Windows PC.

Feel free to change the build settings to suit your own development environment.
Entar wrote:
One side note, you may want to name your .lib something other than engine.lib, maybe something more descriptive or specific like Box2D.lib. Also, it may be a good idea to include the compiled .lib in the SVN download, so that people don't have to compile it every time.

Anyway, I've been trying to get my program to work and it seems that in Release mode, when I add the Box2d.lib (I renamed it) library to my include list, I get a bunch of errors like these:

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)

What's the deal?

I was JUST dealing with this issue. There are 6 (I'm not sure what to call them) "compile modes":

LIBCMT.lib is 'Multithreaded',
LIBCMTD.lib is 'Debug Multithreaded',
MSVCRT.lib is 'Multithreaded DLL',
MSVCRTD.lib is 'Debug Multithreaded DLL',
LIBC.lib is 'Single-Threaded' and
LIBCD.lib is 'Debug Single-Threaded'

You need to make sure all the libraries and your executable are compiled using the same mode. Obviously, you'll set all your Release modes to one and the Debug modes to the debug version of that one. After you do this you should stop having library conflicts.

Personally, I'm confused about how libraries like opengl32.lib work with all other libraries. What mode they compiled in? Or are they just different sorts of libraries? If anyone can answer me this I'd be thankful.
If I compile my program in Debug Multithreaded DLL, it doesn't have the errors, but on some computers it won't run because the program has "wrong program configuration" or something, according to an error popup. However, I will try compiling the Box2D .lib in Multi-threaded mode, then try using that.

EDIT: OK, tried that, Box2D .lib was previously compiled in Multi-threaded Debug, and after changing it I only got one error on compile of my other program:

libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)
The OpenGL library is a stub for opengl32.dll. Now most people already have the DLL on their system, so you don't need to distribute it with your code.
Entar wrote:
If I compile my program in Debug Multithreaded DLL, it doesn't have the errors, but on some computers it won't run because the program has "wrong program configuration" or something, according to an error popup. However, I will try compiling the Box2D .lib in Multi-threaded mode, then try using that.

EDIT: OK, tried that, Box2D .lib was previously compiled in Multi-threaded Debug, and after changing it I only got one error on compile of my other program:

libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)


So you changed Box2D to Multithreaded, recompiled it, made sure your program was set to Multithreaded, and when you compiled it you got that error?
Yep.

EDIT: I just found out, it seems I've been linking against the debug version of the library all along. When I compiled with the release version, it did not give me any errors on compile, but crashed when I started it up. I debugged and found that it crashed in b2BroadPhase::CreateProxy.

EDIT: Maybe I should just try basing my projects on the HelloWorld project file that comes with Box2D, I always hated messing with compiler options...
I wonder if one project has C++ exceptions enabled but the other doesn't?
It's probably just me doing something stupid. I've never liked or been good at working with the compile/build settings in the project and solution files. I couldn't even get SDL and OpenGL to work with the HelloWorld project 🙁
Think you could include somewhere a project file with a very basic implementation of Box2D with OpenGL and SDL to get people started with Box2D and visual rendering? I for one absolutely hate messing with project settings and stuff, I'm better with the code, and wish I didn't have to touch the stuff... ever. But maybe that's just me.

Are you developing Box2D on Windows XP?

Original thread: https://box2d.org/forum/viewtopic.php?t=20