error LNK2019: unresolved external symbol referenced in function main

assembly, c++, visual-studio-2012, x86-64

Solution

extern "C" implies a leading underscore (c-style function naming). Just prefix your function in .asm file and it'll start linking.

UPD: if your project does not build, be sure, you included MASM build customizations: go to project Context Menu -> Build Customizations... -> check the tickbox for masm (.targets, .props).

Then go to properties of you .asm file and select Item Type as 'Microsoft Macro Assembler'.

Problem

Am trying to run my simple assembly code in C++.I have only two files ".cpp" file and ".asm" file. On compiling it gives an error (see below ).I would appreciate if anyone could help...:) This is my "main.cpp" file ``` #include <iostream> using namespace std; extern "C" int GetValueFromASM(); int main(int argc, char *argv[]){ cout<<"value is:"<<GetValueFromASM()<<endl; cin.get(); return 0; } ``` Also i have a simple "asm.asm" file ``` .code GetValueFromASM proc mov rax,3254 ret GetValueFromASM endp end ``` When try to build i get this error : ``` 1>main.obj : error LNK2019: unresolved external symbol GetValueFromASM referenced in function main 1>..\visual studio 2012\Projects\AllAssembly\x64\Debug\AllAssembly.exe : fatal error LNK1120: 1 unresolved externals ``` I tried go to PROPERTIES->LINKS->ADDITIONAL LIBRARY DIRECTORIES and change the path but it didn't work. I tried also go to LINKER->SYSTEM->SUBSYSTEM and Select "Windows (/SUBSYSTEM:WINDOWS)" or "Console (/SUBSYSTEM:CONSOLE)" but neither one worked. Can anyone help !!..BIG THANKS

Original source