Problems Linking, in Visual Studio 2012

537df819fc3266fe
Posts: 5
Joined: Sun Nov 18, 2012 4:43 pm

Problems Linking, in Visual Studio 2012

Post by 537df819fc3266fe »

Hi.
I've successfully compiled Bullet 2.81, and can run the demos. When trying to link the libraries in my own, I'm getting errors. I've reduced the code to:

Code: Select all

#include "btBulletDynamicsCommon.h"

int main(int argc, char** argv)
{
    btBoxShape* box = new btBoxShape(btVector3(1, 1, 1));
    return 0;
}
my Linking Errors are:

Code: Select all

1>------ Build started: Project: HelloBulletApp, Configuration: Release Win32 ------
1>  main.cpp
1>  main.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
1>BulletCollision.lib(btCollisionShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
1>BulletCollision.lib(btConvexShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
1>BulletCollision.lib(btPolyhedralConvexShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
1>BulletCollision.lib(btConvexPolyhedron.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
1>LinearMath.lib(btConvexHullComputer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
1>LinearMath.lib(btGeometryUtil.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>c:\path\to\HelloBulletApp\HelloBulletApp\Release\HelloBulletApp.exe : fatal error LNK1319: 6 mismatches detected
========== Build: 0 succeeded, 1 failed, 4 up-to-date, 0 skipped ==========
I'm getting the same errors if I build in Debug mode.
I've tried: but to no avail.

Is there anything I can do?
537df819fc3266fe
Posts: 5
Joined: Sun Nov 18, 2012 4:43 pm

Re: Problems Linking, in Visual Studio 2012

Post by 537df819fc3266fe »

So the hint was in the error (surprisingly)
I needed to use the static runtime for my project.
In the preferences pane, go to C/C++, then Code Generation, and change Runtime Library to Multi-Threaded (/MT)
Fixed it for me.
jdowner
Posts: 7
Joined: Fri Jan 06, 2012 1:04 pm

Re: Problems Linking, in Visual Studio 2012

Post by jdowner »

As the error says, there is a conflict in the runtime libraries being used. It looks like you are using a different runtime library to what was used to build bullet. The runtime library can be set by opening the solution properties -> Configuration Properties -> C/C++ -> Code Generation. Then you will see on the right a set of values, one of them will be for 'runtime library'. The important choice is whether to use the DLL runtime or not. If you currently use a DLL version switch to the non-DLL version, or vice versa. Then try linking again.

-Josh

[edit] Ha! 3 minutes too slow :) Glad you found the solution.
537df819fc3266fe
Posts: 5
Joined: Sun Nov 18, 2012 4:43 pm

Re: Problems Linking, in Visual Studio 2012

Post by 537df819fc3266fe »

I'll be honest, I posted on StackOverflow and got the answer there, thought I'd at least post the answer here. I'm still terrified that changing the runtime is going to break one of the other libraries I'm using, but for now, it seems ok.