cuốn sách gpt4 ai đã làm

c++ - 无法在 VC++ 中从 NASM 调用 c 函数,除了 main,出现链接错误

In lại Tác giả: Walker 123 更新时间:2023-11-28 07:59:42 34 4
mua khóa gpt4 Nike

谁能告诉我为什么我不能从 NASM 调用任何全局函数,except main ? (在你问之前)是的,我已经在 stackoverflow 和互联网上阅读了大约 8 小时的所有相关问题。

C++ 代码。

void main();

extern "C" void nasm_function(void);

void c_function()
{
}

khoảng trống chính()
{
nasm_function();

hệ thống ("tạm dừng");
}

NASM代码,

extern _c_function
extern _main

segment .text

global _nasm_function
_nasm_function:
call _main
call _c_function

输出,

1>Linking... 1>my_asm.obj : error LNK2001: unresolved external symbol _c_function 1>F:\Projects\OSDev\assmebly_test\Debug\project.exe : fatal error LNK1120: 1 unresolved externals

如您所见,我们没有收到 main 的链接错误。我不知道为什么。 :)

设置,

building nasm using custom-build-rules with nasm.exe -f win32 
Calling convention is __cdecl (/Gd)
Visual Studio 2008
NASM version 2.05
Didn't include my_asm.obj as a input to linker

谁能告诉我这是什么问题?提前致谢。 (请注意,这是一个示例程序,但仍然存在问题)

câu trả lời hay nhất

Vấn đề là名称修改。解决方案是 extern "C".

关于c++ - 无法在 VC++ 中从 NASM 调用 c 函数,除了 main,出现链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11816829/

34 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress