错误LNK2019:​​在主函数中引用解析的外部符号 [英] error LNK2019: unresolved external symbol referenced in function main

查看:312
本文介绍了错误LNK2019:​​在主函数中引用解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行我的简单组装code在C ++中,我只有两个文件的.cpp文件和.ASM文件。在编译它给出了一个错误(见下文)。我将AP preciate如果有人可以帮助...:)

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...:)

这是我的的main.cpp文件

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;
}

另外我有一个简单的asm.asm文件

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.

我也尝试去连接器 - >系统 - >子系统和选择的Windows(/子系统:WINDOWS)或
控制台(/子系统:CONSOLE),但没有一个奏效。谁能帮助!!非常感谢

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

推荐答案

为externC意味着一个前导下划线(C风格的函数命名)。只需preFIX的功能.ASM文件,它会开始链接。

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

UPD:如果你的项目没有建立,可以肯定,你包括MASM建立自定义:去项目的上下文菜单 - >自定义生成... - >检查tickbox为MASM(.targets,.props)

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).

然后去你的属性.ASM文件,然后选择项目类型为Microsoft宏汇编。

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

这篇关于错误LNK2019:​​在主函数中引用解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆