问题描述
我在从 Visual Studio(Win10 x64、Visual Studio 2015)中创建的 asm 项目中调用 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
链接器输出参数:
/OUT:"C:UsersappleDocumentsSP_Lab7DebugSP_Lab7_Demo.exe"/清单:否/NXCOMPAT/PDB:"C:UsersappleDocumentsSP_Lab7DebugSP_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/增量:否/PGD:"C:UsersappleDocumentsSP_Lab7DebugSP_Lab7_Demo.pgd"/SUBSYSTEM:WINDOWS/MANIFESTUAC:"level='asInvoker' uiAccess='false'"/ManifestFile:"DebugSP_Lab7_Demo.exe.intermediate.manifest"/错误报告:提示/NOLOGO/TLBID:1
如果我注释 call print
,那么一切都会正常执行(甚至是 Windows API 函数).有没有办法从 asm 文件调用 C 函数而不创建包含 的 cpp 文件?可以吗?
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?
推荐答案
Microsoft 在 VS 2015 中重构了大部分 C 运行时和库.某些函数不再从 C 库(有些在 C 头文件中定义).Microsoft 有一些兼容性库,例如 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.
改变平台工具集:下拉Project
菜单;选择属性...
;转到Configuration Properties
/General
,并将Platform Toolset
更改为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 标准库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!