0

It's a bit annoying.

I have a project that is entirely dynamically linked, but I want to use a library that seems to be only designed to be statically linked, using the /MT flags, Is it possible to build a separate dll to link to the static libs and then link to that In my project?

I apologise for the rushed explanation, I'm quite tired.

The library in question is the bullet physics library.

Edit: Well, with more googling, it appears that there can be a /MD/MDd compiled version, though I'm not sure where It's located.

Edit(for anyone interested): According to this page: http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=3846

"If your entire engine is compiled with the /MD flag then you would use the 'release DLL' version of bullet. You should not mix libraries compiled with /MD with ones compiled with /MT. That's the main difference. There is no "separate DLL (.dll)" files for bullet."

Edit: And If I build it using the MSVC Runtime library, then it fails.

In short, I have no idea what to do.

He's what I'm doing:

Building the whole library in cmake, using the Visual studio 12, 2013 compiler. Then building the project built by cmake, to build all the required projects.

This is the supplied instructions. Here

Last Edit:Thank you all so much for you help! I managed to build it in the end

Sorry for any spelling mistakes, I was quite tired at the time :3

ComedyGold
  • 11
  • 5
  • I believe the answer is no, because the runtime doesn't match. You can end up with corrupted memory at worst, and link failure at best, I think. – Lynden Shields Jan 22 '15 at 11:51
  • I hope I'm wrong as I'd be interested in being able to do this too, as well as learning more about it – Lynden Shields Jan 22 '15 at 11:52
  • It's really quite frustrating, and the internet is actually quite empty of information on the topic, including their forums. – ComedyGold Jan 22 '15 at 12:00
  • @LyndenShields: yes, you can create a wrapper DLL around a static lib. OP will just have to build the bullet physics library using the same compiler and runtime as the other components they have in their system - so, a single runtime (although BPL supports a "dynamic build" option in their solution file, it just means to use the DLL version of MSVCRT - you still get a static lib for BPL itself). So, one common runtime environment makes a wrapper DLL okay. If OP could not build BPL themselves, they'd really be screwed. Now, they're just seriously inconvenienced. As if that's better. :) – frasnian Jan 22 '15 at 12:01
  • 1
    RE: /MD and /MDs version of the library, you still don't get a static lib for the bullet library - you get a static library that it just uses the DLL version of the MSVC runtime. – frasnian Jan 22 '15 at 12:03
  • I was under the impression that the issue OP was having was because the library only came with the static library runtime available. If that's not the case then I agree. But I'd still like to know more, because I'm having that problem myself, and I have an unanswered question that's very similar – Lynden Shields Jan 22 '15 at 12:03
  • @LyndenShields: got link? – frasnian Jan 22 '15 at 12:05
  • http://stackoverflow.com/q/28080878/78823 – Lynden Shields Jan 22 '15 at 12:06
  • @LyndenShields I was under that Impression too, though it may now appear otherwise, still confused though, albeit slightly less™. – ComedyGold Jan 22 '15 at 12:06

1 Answers1

1

Short answer, yes.

Although you could just have the dynamic libraries link to it, there are scenarios where this may cause serious problems, depending on how the library was written (state information, etc.).

Although it's more work, a wrapper DLL is probably the safest course of action. However, this is offset by the fact that you only need to wrap the functions actually called from the various components of your application, not the entire API provided by the library. Also, you'll need to have some kind of slight rename to the functions you actually wrap, to prevent ambiguity.

On edit: Just took a look at the bullet physics library, as I was not personally familiar with it and was curious about your options after I initially answered. If they're that explicit about not supporting dynamic builds for the library, I think wrapping whatever functions you actually use would definitely be safest. That sucks. I hope it's not too large of a cross-section.

frasnian
  • 1,973
  • 1
  • 14
  • 24
  • The problem explicitly, is that the bullet library is compiled with the /MT flags, and from my understanding, you cannot link with two runtimes. – ComedyGold Jan 22 '15 at 11:48
  • According to the cmake instructions, you're to compile it with the MSVC runtime library, but when I do, it fails. – ComedyGold Jan 22 '15 at 12:23
  • What versions of Bullet and Visual Studio are you using? The latest VS solution I saw was for VS2010 for Bullet 3. The latest version of VS for Bullet 2.x is (I believe) VS2005. Also, how/where does it fail (compiler, linker) and with what messages? – frasnian Jan 22 '15 at 12:28
  • Rebuilding it with different options, I'll post in a sec. I'm building bullet3 to include it in Visual Studio 2013 for Desktop Edit: "131 errors, LNK1169: one or more multiply defined symbols found" and "Error 665 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in GpuDemo.obj" etc – ComedyGold Jan 22 '15 at 12:31
  • Error 539 error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP120D.dll) – ComedyGold Jan 22 '15 at 12:37
  • In the project you're building bullet with, you need to change the runtime library in the code generation page to /MDd for multithreaded dll debug, even though you're building a static library. – Lynden Shields Jan 22 '15 at 12:40
  • For clarification; change each project in Bullet_Physics.sln to use /MD? – ComedyGold Jan 22 '15 at 12:42
  • One of the projects within the solution will be the one that outputs the .Lib file – Lynden Shields Jan 22 '15 at 12:44
  • Thats the one I'm talking about. Though I don't know how that solution works, you might need to do it for its internal dependencies, or you might be able to do it all at once with a cmake setting, if that's what you're using – Lynden Shields Jan 22 '15 at 12:46
  • Compiling with the MSVC runtime appears to make the projects with /MD anyway. – ComedyGold Jan 22 '15 at 12:50
  • There are many different msvc runtimes, /MDd being one of them. /MD, /MT and /MTd are all different. Your entire project and all is dependencies need to have the same one for the linking and running to work – Lynden Shields Jan 22 '15 at 12:54
  • The compiler version is also part of the run time so your whole project and all its dependencies need to be built with the same compiler version too – Lynden Shields Jan 22 '15 at 12:59
  • Thank you all so much for you help! I managed to build it in the end. – ComedyGold Jan 22 '15 at 13:33
  • 1
    Did you end up writing a wrapper dll, or did you just link to the static library from one of your dlls or the application itself? – Lynden Shields Jan 22 '15 at 21:09