简体   繁体   中英

Question about compile and link stages and machine type

I am using the Visual Studio 2019 product for Windows development on a 64 bit Windows and if I investigate the differences between the compilation and linking of 32 or 64 bit programs I only notice a difference in the linking stage. 32 bit linking specifies /MACHINE:X86 whilst 64 bit linking specifies /MACHINE:X64

However, this Microsoft link:

https://learn.microsoft.com/en-us/cpp/build/reference/machine-specify-target-platform?view=msvc-170

has this comment about the /MACHINE option: Usually, you don't have to specify the /MACHINE option. LINK infers the machine type from the.obj files.

So I am confused about how the Microsoft compiler directs either 32 or 64 bit output.

Is it at the compilation stage that object files have a platform designation, ie 32 or 64 bit?

Or is the target platform only specified at the linker stage?

Or is the target platform somehow controlled via the location of cl.exe which is run to generate the executable? For example, on my PC, cl.exe is located in 2 separate places:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64

and

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX64\x86

Each cl.exe only supports one architecture. Just running cl.exe should tell you its target or you can look at the options for /arch .

Object files contain CPU specific code. .obj files are inCOFF format and contain information about the CPU.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM