Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Visual C++ Redistributable Package Required?

Tags:

c++

visual-c++

If the code compiled by a visual C++ compiler is straight C++, why do you need a redistributable package? Does this make your code platform dependant? Does using the visual C++ compiler with the redistributable package provide any advantage over using another IDE along with g++?

like image 336
Alidaco Avatar asked Jan 03 '12 04:01

Alidaco


3 Answers

There is no such thing as "Straight C++". There will always be some library functions that you are calling here and there in your code, and even if you are very careful not to, there will be some functions that will need to be called simply by code emitted by the compiler. For example if you have the following loop:

for( int i = 0;  i < count;  i++ )
    array1[i] = array2[i];

The compiler will replace it with code which simply copies the memory over. And if you are compiling for smaller size instead of speed, this will be a call to a function very much like memmove().

Also, you may have some floating point operations for which there exist no direct x86 equivalent instructions; these will also be implemented with function calls. And the list goes on.

This does not make your code platform dependant, because on a different platform the compiler of that plafrom will compile the same code of yours to go with whatever is the C++ runtime for that platform.

Luckily, the C++ runtime does not have to be a separate entity from your application. Check your compiler and linker options; you should be able to produce a single executable which contains both. If you have found that g++ does not require a separate runtime, it is because it does exactly that by default.

like image 138
Mike Nakis Avatar answered Oct 03 '22 13:10

Mike Nakis


The code is not platform dependent, the resulting executable is. It is linked against the MS libraries with the standard library implementation, that are included in the redistributable as DLL's.

IIRC there should be an option for static linking of everything, so that you wouldn't need the additional redistributable, but the resulting binary would still be platform dependent - for example you can't run a windows binary on a UNIX system (without WINE at least).

like image 35
littleadv Avatar answered Oct 03 '22 13:10

littleadv


The C++ redistributable are specific to the IDE that you are using ("IDE" I say, but that's really specific to the compiler, yet the IDE & compiler are both being assigned new versions as things move along.)

It is made specific to that IDE, but not to the Win OS. So it should be backward compatible (assuming you're not using new APIs, obviously.) Actually, this is done so it is backward compatible (and not the other way around as you're thinking.) This allows you to use the latest greatest IDE version (10, 11, 12...) and still run your code on Win2k!

Now, of course, it's much different from Linux where you're expected to recompile on each main version anyway. Most Unix systems will work that way.

I do not know of a way to compile C++ statically so as to be able to avoid those redistributables. It may be possible, although it would certainly make your .exe very big.

like image 26
Alexis Wilke Avatar answered Oct 03 '22 14:10

Alexis Wilke