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
LNK2019 can occur when a declaration exists in a header file, but no matching definition is implemented. For member functions or static data members, the implementation must include the class scope selector. For an example, see Missing Function Body or Variable.
To fix this issue, build all the object files and libraries with the same version of the compiler before linking them together.
Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With