简体   繁体   English

错误LNK2019:函数main中引用的未解析的外部符号

[英]error LNK2019: unresolved external symbol referenced in function main

Am trying to run my simple assembly code in C++.I have only two files ".cpp" file and ".asm" file. 我试图用C ++运行我的简单汇编代码。我只有两个文件“.cpp”文件和“.asm”文件。 On compiling it gives an error (see below ).I would appreciate if anyone could help...:) 在编译时会出现错误(见下文)。如果有人可以提供帮助,我将不胜感激...... :)

This is my "main.cpp" file 这是我的“main.cpp”文件

#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 我还有一个简单的“asm.asm”文件

.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. 我也试过去LINKER-> SYSTEM-> SUBSYSTEM并选择“Windows(/ SUBSYSTEM:WINDOWS)”或“Console(/ SUBSYSTEM:CONSOLE)”但两个都​​没有工作。 Can anyone help !!..BIG THANKS 任何人都可以帮助!! ..非常感谢

extern "C" implies a leading underscore (c-style function naming). extern“C”表示前导下划线(c风格函数命名)。 Just prefix your function in .asm file and it'll start linking. 只需将您的函数添加到.asm文件中,它就会开始链接。

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). UPD:如果您的项目没有构建,请确保您包含MASM构建自定义:转到项目上下文菜单 - >构建自定义... - >选中masm的复选框(.targets,.props)。

Then go to properties of you .asm file and select Item Type as 'Microsoft Macro Assembler'. 然后转到.asm文件的属性,并选择项类型为“Microsoft宏汇编程序”。

I confused it with 32bit. 我把它与32位混淆了。 :( :(

So this should work for 64bit. 所以这适用于64位。

section .code
global GetValueFromASM

GetValueFromASM:
    ...

No Changes i made to the codes.I just changed some configurations as "Arty" suggests. 我没有对代码进行任何更改。我只是更改了一些配置,如“Arty”所示。

Here is How : Right click your project->Go to Build Customization -> check MASM -> Click OK Then go to properties of your .asm file and select Item Type as 'Microsoft Macro Assembler'. 方法如下:右键单击您的项目 - >转到构建自定义 - >检查MASM - >单击确定然后转到.asm文件的属性,并选择项类型为“Microsoft宏汇编程序”。

You Done!!..Thanks to Arty & Devolus for the help. 你做完了!!感谢Arty&Devolus的帮助。

Can be helpful For similar problem: http://scriptbucket.wordpress.com/2011/10/19/setting-up-visual-studio-10-for-masm32-programming/ 对于类似的问题可以有所帮助: http//scriptbucket.wordpress.com/2011/10/19/setting-up-visual-studio-10-for-masm32-programming/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误LNK2019:函数_main中引用的未解析的外部符号“...” - error LNK2019: unresolved external symbol “…” referenced in function _main 错误LNK2019:函数_main中引用的未解析的外部符号 - error LNK2019: unresolved external symbol referenced in function _main LNK2019:函数__tmainCRTStartup中引用的未解析的外部符号_main - LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup LNK2019:未解析的外部符号...在函数_main中引用 - LNK2019: Unresolved External Symbol … Referenced in function _main LNK2019:函数___tmainCRTStartup中引用了未解析的外部符号_main - LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup 错误LNK2019:函数中引用的未解析的外部符号“” - error LNK2019: unresolved external symbol “” referenced in function 错误 LNK2019 未解析的外部符号 dbbind 在 function 中引用 - error LNK2019 unresolved external symbol dbbind referenced in function Clrdump(C ++)错误LNK2019:函数_main中引用的未解析的外部符号__imp__RegisterFilter @ 8 - Clrdump (C++) error LNK2019: unresolved external symbol __imp__RegisterFilter@8 referenced in function _main C ++错误LNK2019:函数_tmainCRTStartup中引用了未解析的外部符号_main - C++ error LNK2019: unresolved external symbol _main referenced in function _tmainCRTStartup 错误LNK2019:函数_main visual c ++中引用的未解析的外部符号 - error LNK2019: unresolved external symbol referenced in function _main visual c++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM