In Visual Studio 2012 what is the difference betwe

2019-04-26 21:45发布

问题:

I am configuring my Projects to build with x86 and x64 bits, in order to do that I had to change the Target Machine for the different Configurations.

I was trying to find where to set the Target Machine for my Native C++ Libraries and I found this post.

However I don't have a Linker in the Native C++ Library projects, I have the "Configuration Properties -> Linker -> Advanced -> Target Machine" option in the C++/CLI projects only.

In the Native C++ Library projects I have a "Librarian" section. I searched and I found that the Target Machine is in: Configuration Properties -> Librarian -> General -> Target Machine.

The Librarian section seems to have less options than Linker.

Are the Librarian and the Linker section the same? On the documentation I searched on google I only see Linker mentioned.

Maybe I have something configured wrong? Or in this post the answer didn't refer to Native C++?

回答1:

Are the Librarian and the Linker section the same? On the documentation I searched on google I only see Linker mentioned.

They are almost the same. Librarian is enabled when your project is going to be a static lib. Linker is for executables and dynamic libraries (dll).

While dynamic libraries will be linked dynamic to the excecutable your are building, which means the dll have to be around while executing, static libs will be part of the executable. Static libraries mustn't be linked to some dynamic lib, since the linking should be done while generating the executable, apart from that it would cause ambiguity. This is why the Librarian options are reduced. (e.g. there is no Input options).

Maybe I have something configured wrong? Or in this post the answer didn't refer to Native C++?

his project generates a dll, not a static lib. Check your settings in Configuration Properties -> General -> Configuration Type.



回答2:

You see the Librarian section when you created a static library project. Do beware that such a project is incompatible with code built with the /clr option, managed code is linked at runtime, not build time. Trying to use such the .lib file gives pretty hard to diagnose linker errors when you try to build an assembly. It is okay if you use it for pure native code, the kind built without /clr in effect.

There's very little to a .lib file, it is just a bag of .obj files. Think of it as a .zip archive with a cr*ppy compression rate. The lib.exe utility is there to get .obj and .lib files added and removed from the .lib, think of it as winzip.

So there are indeed very few settings in the General section, there's just not much to lib.exe. Pretty much a one-to-one mapping to the command line options that lib.exe takes. The /MACHINE option (aka Target Machine setting) is not required, it is fixed by the compiler you used. It is documented as:

However, in some circumstances, LIB cannot determine the machine type and issues an error message. If such an error occurs, specify /MACHINE.

So scratch that idea. It is entirely locked in by the Platform selection you used for your project. Standard ones in VS are Win32 to generate 32-bit code and x64 to generate 64-bit code.