gpt4 book ai didi

c++ - 使用 Visual Studio 从 C++ 代码调用程序集过程

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:16:53 25 4
gpt4 key购买 nike

被 Visual Studio、Assembly 和 C++ 困住了

C++:

extern "C" void asm_calculate_reals();
int main()
{
asm_calculate_reals();
return 0;
}

程序集:

PUBLIC _asm_calculate_reals
.386
.model flat, stdcall
option casemap :none
.stack 100h
.code
_asm_calculate_reals PROC
;code goes here
ret
_asm_calculate_reals ENDP
end

当我构建我的项目时,Visual Studio 报告以下错误:

error LNK1120 error lnk1120 1 unresolved externals

我实际上不明白这个简单的程序部分有什么问题。

日志文件:

Build started 16.04.2015 16:53:21.
1>Project "somepath\Reals loop 3variants.vcxproj" in node 2 (targets Build).
1>Link:
somepath\link.exe /ERRORREPORT:PROMPT /OUT:"somepath\Debug\Reals loop 3variants.exe" /INCREMENTAL /NOLOGO somelibs /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"somepath\Debug\Reals loop 3variants.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"somepath\Debug\Reals loop 3variants.lib" /MACHINE:X86 /SAFESEH:NO Debug\main.obj
Debug\reals.obj
1>main.obj : error LNK2019: reference to the unresolved external symbol _asm_calculate_reals in function _main
1>somepath\Debug\Reals loop 3variants.exe : fatal error LNK1120: unresolved identifiers: 1
1>Building project "somepath\Reals loop 3variants.vcxproj" finished (targets Build) with errors.

Build failed.

最佳答案

实际问题出在汇编源代码中的模型定义中。

.model flat, stdcall - 出现错误时。

.model flat, c - 改成这个,按预期工作。

关于c++ - 使用 Visual Studio 从 C++ 代码调用程序集过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29675785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com