【发布时间】:2021-04-20 13:21:33
【问题描述】:
我尝试使用 clang 编译器编译以下示例代码,它工作正常。
- 编译器详细信息:Apple clang 版本 12.0.0 (clang-1200.0.32.28)
- 目标:x86_64-apple-darwin20.1.0
#include <iostream>
#include <stdio.h>
int __cdecl printf(const char* format, ...)
{
std::cout<<"My printf function"<<std::endl;
return 0;
}
int main()
{
printf("Standard printf function\n");
return 0;
}
但是,当我尝试在 Visual Studio 2019 或 g++ 中编译时,它给出了编译错误。
错误 C2084:函数 'int printf(const char *const ,...)' 已经有一个主体
- msvc编译失败的原因是什么?
- 我怎样才能让它工作,我错过了什么?
【问题讨论】:
-
你得到的错误的全文是什么?
-
error C2084: function 'int printf(const char *const ,...)' already has a body
标签: visual-c++ compiler-errors g++ clang++ weak-linking