How to build and link LuaJIT statically (VS 2013) - c++

Premise : I'd like my C++ application not to depend on whatever Microsoft Visual C++ redistributable, so I can ship my executable file that will work out of the box.
What I've done first : switching the runtime library to Multithread (/MT) from DLL Multithread (/MD) in order to avoid the need for msvcr110.dll (and shouldn't VS 2013 require the 120 version, as it's the compiler version ?). To do that I also had to recompile another library I'm using with the same runtime library, and that worked. I had my .exe which could be ran anywhere without problems (or I wasn't aware of, haha).
Then I added some functionalities that make use of LuaJIT. I've built LuaJIT by the msvcbuild.bat provided with the package and it worked like a charm, but now my executable requires the msvcr110.dll to run. I guess that's because LuaJIT was compiled with the /MD flag, but I'd like to know if there is a proper way to do what I want.

You should run msvcbuild.bat with static command line parameter.

I didn't test this, but you most likely need to use the /MT flag on each piece of the compilation you do. In this case, both your main program, and LuaJIT. In that msvcbuild.bat file (https://github.com/luvit/luajit-2.0/blob/master/src/msvcbuild.bat) you can see that they are explicitly specifying /MD (line 17). Methinks that is your problem. Change it to /MT and see.

Related

Why should we set /MT to run executable in another pc

I'm reading about /MT and /MD, but I'm a little confused about it
HEAR is something I don't completely understand :
/MT Causes your application to use the multithread, static version of the run-time library. Defines _MT and causes the compiler to place the library name LIBCMT.lib into the .obj file so that the linker will use LIBCMT.lib to resolve external symbols.
what does it mean?
If you link with /MD or /MDd your program is going to need the CRT dlls in order to run. typically they are called something like msvcp100.dll for the C++ runtime and msvcr100.dll for the C runtime. If you are deploying your application using an installer, you can add a package with these to your installer so the dlls are going to be there when someone runs the application. If on the other hand you are going to deploy your application just as a single stand alone exe, your users are going to need a copy of these dlls. The latest versions of these dlls usually come with windows itself (not the debug ones) but if your user is running an older version of windows it may not have the needed dlls.
Linking your application to the static version of the CRT saves this whole headache for the price that the exe is slightly bigger (since it contains the CRT in it)
If you do use /MT (Static CRT) you have to make sure that everything else that you statically link with uses /MT as well. otherwise you'll end up with an executable where part of the code uses the static CRT and part is still depends on the CRT DLL. Other than defeating the basic purpose not needing the CRT DLL, this can also cause other problems.
To make sure what DLLs your exe depends on you can use the dependency walker.

Compile C++ in VS without requiring MSVCP120D.dll at runtime

I'm trying to make a binary that can be run on any windows machine without the visual c++ stuff installed (I'm assuming that's what MSVCP120D.dll is however my searching was not very fruitful as to what this actually is). I made a game for an assignment and wanted to have other people (non-devs without VS stuff installed), help me test it but they kept getting errors saying that the above dll is missing. I'm not using any Visual C++ stuff and have the /Za flag set to ensure that it's just ANSI C++. Does Visual Studio support compiling ANSI C++ and if so how do I go about making it not use Visual C++ stuff, if it doesn't support this what compiler should I use?
As you can see here, the MSVCP DLL is the platform's implementation of the C++ Standard Library. In short what that means is you cannot distribute your application without needing the "stuff" that these libraries provide. All compilers regardless of platform would need some kind of implementation of the Standard Library. Typically this is distributed in the form of libraries.
However you can distribute your application so that the "stuff" is built in to your program directly, rather than being shipped in a separate DLL. In order to do this, you must statically link your application to the Standard Library.
There are a few ways to accomplish this. One way is in Project Settings. In "Project" > "Configuration Properties" > "C/C++ Code Generation" > "Runtime Library", choose "Multithreaded (/MT)" as opposed to "Mutithreaded (Static)".
By the way, the "D" in "MSVCP120D.dll" you mentioned above means "Debug." This means that you are trying to distribute a debug build of your program. You should (almost) never do this. Distribute release builds instead.
You have three options (in the order I'd recommend):
Don't statically link, instead get people that want to run your game install the visual studio re-distributable package. 32-bit VC 2010 version here: http://www.microsoft.com/en-us/download/details.aspx?id=5555
Statically link the CRT (the dll you don't want to require at runtime) see here for details: How do I make a fully statically linked .exe with Visual Studio Express 2005?
Build an app that doesn't even use the CRT at all. Here you will have to implement your own operator new that calls HeapAlloc(), and operator delete that calls HeapFree(), its an interesting challenge ;). To do this you tell the linker to ignore all default libs.
Build with the static runtime libraries rather than the DLL versions.
Go to Properties, C/C++, Code Generation, Runtime Library and select /MTd or /MT rather than the /MDd and /MD options.
Configure your project to link against the runtime statically rather than dynamically.
First of all the D on the end of the name indicated a debug build. If you make a release build then it will need it without the D. This is important because microsoft do not allow the debug libraries to be distributed without visual studio.
The machine you are trying to run the program on may already have the release runtime installed as lots of programs use it. If not then install http://www.microsoft.com/en-us/download/details.aspx?id=30679 on the machine ( I think that's the right one but can't check at the moment)
You'll want static linking, that 'builds in' the external library calls into your binary. It does have the added affect of larger binary file, but in your case that doesn't sound like that big of a deal.
On a side note, MSVCP120D.dll is the Microsoft Visual C++ 12 debug DLL (dynamic link library) that contains all of debug C++ libaries (i.e. iostream, string, etc). That library is what you would be 'baking in' to your final binary.
Hope that helps.
I encountered this error when I tried to execute my exe on a different machine that had a newer version of Visual Studio on it. You need to change the project properties and re compile in order for this to go away.
To do this:
Open up solution that you are trying to run
Right click on the Project file - > Properties
In Configuration Properties and General, Ensure Platform Toolset is configured to be the correct compiler on your machine. If it is not correct, it should give a message next to it saying that it's not installed.
Build and run the code again and you should no longer get the issue.

Release mode still dependent on MSVCP110D.dll (C++ MSVS)

I am new to C++ programming and had just finished making a simple calculator. I decided to share it with my friends and after several attempts figured out how to compile it in release mode. However, even in release mode it is still dependent on the MSVCP110D.dll. I was wondering if there was a way to fix this?
1) MSVCP110D.dll is the runtime .dll for the "Debug" version of the MS C Runtime Library. So it looks like your .exe might not have been built for "Release" correctly after all.
2) Here is information for the "Visual Studio Runtime Redistributable":
http://www.microsoft.com/en-us/download/details.aspx?id=30679
3) Here is more information on this particular problem:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/e128dff6-cef5-4a81-b6de-fcbcaa7a23bb
Unfortunately the msvcp100D.dll is a debug dll and it isn't included
in the Microsoft Visual C++ Redistrutable package. This is becouse
normally debug version aren't release to other than developer.
Developer have installed it by default with Visual Studio.
You can compile your project in "Release" so all dll which you'll need
will be included in the Microsoft Visual C++ Redistrutable package.
Otherwise you can do the static link of all libraries(specify /MT in
Release and /MTd in Debug configuration into compiler options): but
personally I don't recommend it becouse you put in the executable many
information(used by the debugger) which will slow down your app.
I am guessing your issue is with dependency on the debug version of the dll & not the dependency on the dll itself.
It's highly likely you doing one of these 2 things
compiling with /DDEBUG or /D_DEBUG OR
linking with msvcpd.lib
When you compile with /DDEBUG or /D_DEBUG, and #includeing one of the standard C++ headers, then msvcpd.lib is pulled in (with a #pragma(lib)which leads to a dependency on msvcpd***.dll.
msvcp(d)*.dll is the dll version of the standard C++ library.
If instead, your issue is with a dependency on any version the dll i.e. you want to staticly link with the C++ library, then you can compile your program with _STATIC_CPPLIB.
Are you using any additional libraries?
Maybe you have included a debug version of a dll file with your executeable.

What to do when /MT and /MD both required?

This is a sort of follow-up to this question I posted yesterday. My problem regards which runtime C++ libraries to link against. I am using Qt as a framework and QtCreator for my IDE. According to the digia docs here, Qt has been known to have memory problems when built with the /MT flag (which makes your app run against the static runtime libraries). However, I'm also using a 3rd party driver in this app, and the docs on that app specifically say that it won't build unless you link against the static runtime libraries. Sure enough, it compiles fine with the /MT flag, but gives me about 40 linker errors when I remove that setting. (and so far I'm only including one header file from the driver's static library)
So my question is: what's the correct thing to do here? Is there a way to force the driver to expect the dynamic runtime library? Or should I live with Qt's memory management problem? Or is there a way to have Qt link against the dynamic ones and the driver (and the parts of Boost that it requires) link against the static ones? (and keep in mind that I'm doing this in QtCreator, not studio)
Both /MT and /MD are linker options. If you're building multiple modules, you can have multiple options.
In this case, use /MD for Qt and your own code. Wrap the driver in its own DLL, with a non-CRT-dependent API, and link that DLL with /MT. Using COM might be an option. That's certainly not CRT dependent, but it may be overkill.

Removing msvcp90d.dll dependancy from Windows binary

I have a dll that I distribute that will not run on some windows OS. Using dependancy walker I discover msvcp90d.dll missing on these systems. I DO NOT want any run time dependancies that require the C++ redistributable, and since the application that calls the DLL is not written in C++, it does not have any dependancy on the C++ redistributable.
I am guessing the I left the DEBUG option in the linker preferences on when I compiled the dll which is why it needs msvcp90d.dll?
ADDED:
Appologies, I pasted the wrong dll name in my original question.... too many hours in front of the monitor...
THe dll is a third party dll that I did not write compiled by me in VS2008.
MSVCP90 is nothing to do with debug (that'd be msvcp90d). You can remove your dependency by switching the compiler to /MT (instead of /MD). You also need to ensure that every static library you link to was also compiled /MT.
I recommend against building apps /MT because it has a significant negative effect on system performance and makes servicing take longer in the event of a security issue with the CRT.
Finally, note that /MT means that your CRT is private. So you must ensure that CRT/STL types don't pass across your DLL boundary.
Martyn
Your options as I see them:
Compile the DLL with the /MT option to use static linking to the C runtime.
Continue with dynamic linking to the runtime, but distribute the C runtime with your app.
It needs MSVCP90.dll because the dll was compiled with Visual Studio 2008 most likely. That is the release runtime. The short answer is if you don't want C++ runtime dependencies don't use C++ libraries or applications.
However you can do any of the following to solve your problem:
Install the redistributable to the target system to satisfy the dependency
Remove the dependency on that dll from your application
Recompile the dll against the version of VC you prefer that is already present on the target system