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

标签 c++ visual-studio-2008 visual-c++ linker nasm

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

C++ 代码。

void main();

extern "C" void nasm_function(void);

void c_function()
{
}

void main()
{
    nasm_function();

    system("pause");
}

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

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

最佳答案

问题是名称修改。解决方案是 extern "C"

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

相关文章:

c++ - 成对访问 map 中的值

c# - ThreadPool.RegisterWaitForSingleObject 的正确实现方式

visual-studio-2008 - 开发环境的最佳 SQL Server 设置是什么?

c# - 如何为 Rhino Mocked 对象设置值?

c++ - g++ 和 cilkscreen 用于检测竞争条件

c++ - 使用 libpq/libpqxx 进行输入清理

c++ - 奇怪的段错误

c++ - Visual C++ 2010 Beta 1 是否有 unique_ptr,如果没有,我从哪里可以获得 C++0x 引用实现?

c++ - 使用继承构造函数时 VS2015 内部编译器错误

c++ - 如何使用CMake仅在一种模式下拥有变量