【发布时间】:2012-09-27 21:24:05
【问题描述】:
试图弄清楚如何编译使用 C 和 C++ 文件的应用程序。不是完整的代码,但足以理解:
main.cpp:
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "one.h"
#include "two.h"
int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hInst2, LPSTR lpCmdLine, int nShowCmd) {
FunctionOne();
FunctionTwo();
}
一个.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <gdiplus.h>
#include <gdiplusflat.h>
using namespace Gdiplus;
using namespace Gdiplus::DllExports;
int FunctionOne() {
}
两个.c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int FunctionTwo() {
}
头文件只包含这些函数的定义。
现在,如果我用 main.cpp 编译它,我会得到 FunctionTwo 的“未解析的外部符号”。如果我用 main.c 编译它,我会为 FunctionOne 得到同样的结果。这甚至可能吗?如果可以,我将如何设置项目以正确编译(Visual Studio 2010)?
如果我根据 main 的扩展名注释掉备用函数,它编译得很好。
谢谢!
【问题讨论】:
-
查看 -> stackoverflow.com/questions/12573816/… - MSVS 将
.c文件编译为 C 并将.cpp文件编译为 C++。
标签: c++ c visual-studio-2010 compilation compiler-errors