在Visual Studio中的ASM调用C标准库函数 [英] Call C standard library function from asm in Visual Studio
问题描述
我有在Visual Studio中创建ASM项目(Win10 64时,Visual Studio 2015年)调用C函数的一个问题。项目由一个ASM文件:
I have a problem with calling C function from asm project created in visual studio (Win10 x64, Visual Studio 2015). Project consist of one asm file:
.586
.model flat, stdcall
option casemap:none
includelib msvcrt.lib
ExitProcess PROTO return:DWORD
extern printf:near
.data
text BYTE "Text", 0
.code
main PROC
push offset text
call printf
add esp,4
invoke ExitProcess,0
main ENDP
end main
当我建的项目,连接器输出错误:
When I build project, linker outputs the error:
错误LNK2019解析的外部符号_printf中引用
函数_main @ 0
Error LNK2019 unresolved external symbol _printf referenced in function _main@0
连接器输出参数:
/ OUT:C:\\用户\\苹果\\文档\\ SP_Lab7 \\调试\\ SP_Lab7_Demo.exe
/ MANIFEST:NO / NXCOMPAT
/PDB:\"C:\\Users\\apple\\Documents\\SP_Lab7\\Debug\\SP_Lab7_Demo.pdb
/ DYNAMICBASEKERNEL32.LIBUSER32.LIBGDI32.LIBwinspool.lib
comdlg32.libadvapi32.libSHELL32.LIBole32.liboleaut32.lib
UUID.LIBodbc32.libodbccp32.lib/ MACHINE:X86 / SAFESEH:NO
/增量:NO
/PGD:\"C:\\Users\\apple\\Documents\\SP_Lab7\\Debug\\SP_Lab7_Demo.pgd
/子系统:WINDOWS / MANIFESTUAC:级别='asInvoker'uiAccess ='假'
/ManifestFile:\"Debug\\SP_Lab7_Demo.exe.intermediate.manifest
/ ERRORREPORT:PROMPT / NOLOGO / TLBID:1
/OUT:"C:\Users\apple\Documents\SP_Lab7\Debug\SP_Lab7_Demo.exe" /MANIFEST:NO /NXCOMPAT /PDB:"C:\Users\apple\Documents\SP_Lab7\Debug\SP_Lab7_Demo.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MACHINE:X86 /SAFESEH:NO /INCREMENTAL:NO /PGD:"C:\Users\apple\Documents\SP_Lab7\Debug\SP_Lab7_Demo.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\SP_Lab7_Demo.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
如果我评论调用打印
,那么一切都将正常执行(甚至是Windows API函数)。有什么办法来调用ASM文件C函数,而无需创建包含CPP文件< cstdio>
?
是否有可能呢?
If I comment call print
, then everything executes normally (even Windows API function). Is there any way to call C function from asm file without creating cpp file that includes <cstdio>
?
Is it possible to do?
推荐答案
微软重构大部分的 C 的运行时间和图书馆在2015年VS某些功能不再从出口的 C 的库(有些是在 C 的头文件中定义)。微软有一个像的 legacy_stdio_definitions.lib 的一些兼容性库和 legacy_stdio_wide_specifiers.lib 的,但你也可以选择使用旧的Visual Studio 2013平台工具与旧的 C 的库。
Microsoft refactored much of the C runtime and libraries in VS 2015. Some functions are no longer exported from the C library (some are defined in a C header file). Microsoft has some compatibility libraries like legacy_stdio_definitions.lib and legacy_stdio_wide_specifiers.lib, but you can also choose to use the older Visual Studio 2013 platform toolset with the older C libraries.
要改变平台工具集:在项目
菜单拉下来;选择属性...
;转到配置属性
/ 常规
,并更改平台工具集
为的Visual Studio 2013(V120)
To change the platform toolset: pull down the Project
menu; select Properties...
; go to Configuration Properties
/General
, and change Platform Toolset
to Visual Studio 2013 (v120)
这篇关于在Visual Studio中的ASM调用C标准库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!