Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用C++;MASM链接器中的函数错误 我现在尝试从汇编程序中运行外部C++函数。我的汇编程序运行正常,但我不断收到一个链接器错误,上面说:_C++_Assembly_Visual C++_X86_Masm - Fatal编程技术网

调用C++;MASM链接器中的函数错误 我现在尝试从汇编程序中运行外部C++函数。我的汇编程序运行正常,但我不断收到一个链接器错误,上面说:

调用C++;MASM链接器中的函数错误 我现在尝试从汇编程序中运行外部C++函数。我的汇编程序运行正常,但我不断收到一个链接器错误,上面说:,c++,assembly,visual-c++,x86,masm,C++,Assembly,Visual C++,X86,Masm,“错误LNK2019未解析的外部符号_testFunc@0在函数中引用__main@0" 我想知道为什么我会犯这个错误,我想是因为我不知怎么把我的C++函数导入到我的ASM程序中,但是我看到其他人也用类似的方式来做。 这是我的汇编代码: ; Created with MASM .386 .MODEL FLAT, stdcall .STACK 100h ExitProcess PROTO, dwExitCode:DWORD extern testFunc : proto .CODE _m

“错误LNK2019未解析的外部符号_testFunc@0在函数中引用__main@0"

<>我想知道为什么我会犯这个错误,我想是因为我不知怎么把我的C++函数导入到我的ASM程序中,但是我看到其他人也用类似的方式来做。 这是我的汇编代码:

; Created with MASM
.386

.MODEL FLAT, stdcall

.STACK 100h

ExitProcess PROTO, dwExitCode:DWORD

extern testFunc : proto

.CODE
_main PROC

    call testFunc
    xor edi, edi

INVOKE ExitProcess, 0

_main ENDP
END

和我的C++代码:

#include <iostream>
using namespace std;

extern "C" void _main();

extern "C" void testFunc()
{
    cout << "Hello world";
}

int main()
{
    _main();

    return 0;
}
#包括
使用名称空间std;
外部“C”void_main();
外部“C”void testFunc()
{

您可以声明
。模型平面,stdcall
。您应该定义函数

extern "C" __stdcall void testFunc()

这不是我在这里要做的吗?“extern testFunc:proto”您没有执行
extern testFunc:proto c
和声明默认stdcall。我想我明白您的意思,但是我仍然收到一个错误,说“符号语言属性冲突:testFunc”@Suezzeus:不过,这是另一个错误;这个答案正确地修复了stdcall函数的符号名称混乱(包括
@n
,返回时弹出的字节数)是的,这是真的。谢谢你解释这部分。我相信我理解了!我会先解决一下它。什么C编译器?MSVC?如果这是普通Windows,
foo
的asm符号名是32位代码(不是64位)中的
\u foo
。因此,在asm中,您的
\u main
定义是定义C函数
main
,而不是
\u main
,除非MASM添加了另一个级别的损坏。最好选择完全不同的东西,例如
asm\u main
,它不会意外地发生冲突。是的,使用visual studio community 2019。即使我更改了它,也会ys没有找到函数定义“asm_main”。我觉得我缺少了一些基本的理解。哇,我没有返回函数!