Purpose of “Target machine” field in Visual studio -> Linker-> Advanced Options->Target Machine

廉价感情. 提交于 2019-12-13 21:13:23

问题


I'm porting a 32-bit C++ app to 64-bit (using VS2008). I'm not sure what does this field mean in the VS2008 ::

Visual studio ->Configuration Properties-> Linker-> Advanced Options->Target Machine.

By default it's value is set to "Not set". Is it compulsory to change it's value to "MACHINEx64" if I want my application to be ported to 64-bit executable.


回答1:


Yes, this is a very important option. It sets the IMAGE_FILE_HEADER.Machine field in the executable file. The very first field of the EXE or DLL header.

Windows check this when it loads an EXE and knows whether it needs to create a 32-bit or a 64-bit process from that field. The only reason it is a the Linker + Advanced property page is because you don't normally change it. The setting is pre-selected by the project configuration you created. If you get "Not Set" then you are basically doing it wrong, hard to guess what you are doing.

Assuming you have a properly configured project that builds a working 32-bit build for your program, you create the 64-bit build with Build + Configuration Manager. In the "Active solution platform" combobox at the upper right, select <New...>. Pick "x64" in the dialog. Hopefully the other defaults (Copy settings from = Win32, Create new project platforms ticked) are correct for yours. Go back to the Linker + Advanced property page and the setting should have changed to MachineX64.




回答2:


This option relates to the linker option /MACHINE and is a hint for the linker for what target architecture to link the object code if he (the linker) cannot determine this from the object file. As MSDN states you usually have not to specify this. So no you don't need to explicitly specify this flag when porting your code.



来源:https://stackoverflow.com/questions/18572981/purpose-of-target-machine-field-in-visual-studio-linker-advanced-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!