如何解析"printf"的符号?而不是"_printf"在win32控制台上? [英] How to resolve the symbol of "printf" instead of "_printf" on win32 console?
问题描述
测试平台是Windows 32位.
test platform is windows 32bit.
所以基本上我想在以下命令中进行汇编+链接一小段汇编代码:
So basically I want to assembly + link a snippet of assembly code in these commands:
nasm -fwin32 test.s
cl test.obj /link msvcrt.lib
它说:
error LNK2001: unresolved external symbol printf
在我的代码中,我确实有这样的函数调用:
In my code I do have function call like this:
call printf
所以我将所有这些都更改为
So I changed all of these into
call _printf
它有效.
我不熟悉Windows上的编程,但是有什么办法可以解决 printf 的外部符号?
I am not familiar with programming on windows, but is there any way to resolve the external symbol of printf ?
因为我正在执行一些自动转换任务,所以用 _ 开始的所有函数调用的转换应该非常繁琐...
Because I am doing some automatically transform task, and transformation of all the function calls with _ begin should be very tedious...
任何人都可以给我一些帮助吗?谢谢!
Can anyone give me some help..? Thank you!
推荐答案
MSVCRT与使用Visual C ++编译的所有内容一样,都导出cdecl
函数替代此行为,但是由于MSVCRT不是您的库,则无法更改.
MSVCRT, like everything compiled with Visual C++, exports cdecl
functions using an underscore prefix. For your own libraries, you can override this behaviour, but since MSVCRT is not your library, you can't change that.
您确实必须使您的程序集调用使用下划线名称.但是nasm有一个选项, --prefix
,这使操作更加容易:--prefix _
. (感谢弗兰克·科特勒(Frank Kotler)提到这一点.)
You really are going to have to make your assembly calls use the underscore name. But nasm has an option, --prefix
, which makes this easier: --prefix _
. (Thanks to Frank Kotler for mentioning this.)
这篇关于如何解析"printf"的符号?而不是"_printf"在win32控制台上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!