开发者

Trying to understand the interaction between compiler and linker for multi-platform compilation

I have a C++ Visual Studio project which I'm trying to compile for x86 and x64 architecture. 开发者_如何学编程I've googled and found a lot information how to do it and it seems to work, but it left me deeply confused about what is going on behind the curtains.

Apperently, the only difference in the settings is a switch in the linker command line flags (to be precise, it's the /MACHINE flag).

If that's the case however, then the object files of the compilation must be platform independent - which is somehow the exact opposite of what I always assumed it to be, since object files are supposed to be sequences of machine code which in turn should be platform dependent.

So, my question is: which part(s) of the build process does not behave the way I thought it would?

Thanks for your time and wisdom!

Michael


When compiling for 32-bit x86, Visual Studio uses the compiler \Program Files\Microsoft Visual Studio 10.0\VC\bin\cl.exe. When compiling for 64-bit x86, Visual Studio uses the compiler \Program Files\Microsoft Visual Studio 10.0\VC\bin\amd64\cl.exe. The first compiler produces 32-bit object files, the second produces 64-bit object files. This can be seen by running dumpbin.exe on the object files to see their specified architecture.

The compiler invocation remains the same (more or less) -- what changes is the executable $PATH that is set before building. By pointing the PATH to the 32-bit or 64-bit directory, it sneakily changes the whole set of programs that is run to build your project. You can see this by looking at the Project Properties > Configuration Properties > VC++ Directories > Executable Directories, and clicking on "Edit". In the "Inherited Values" box you'll see the path for the current Configuration and Platform.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜