试图弄清楚如何让使用 C 和 C++ 文件的应用程序进行编译。不是整个代码,但足以理解:
主.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 的扩展名注释掉备用函数,它编译得很好。
谢谢!