gpt4 book ai didi

c - VS 2013错误C1853尝试构建DLL(但不使用预编译头集)

转载 作者:行者123 更新时间:2023-11-30 17:05:43 29 4
gpt4 key购买 nike

您好,我正在尝试使用 VS2013 社区版用 C 语言构建最简单的 DLL。我在选项中设置了“不使用预编译头”(尽管不知何故项目创建向导似乎表明使用预编译头是强加的,因为它是一个灰色的检查选项。无论如何,我决定使用与项目属性关联的菜单将其关闭。)但我仍然收到此错误消息

Error 1 error C1853: 'Release\ExportDLLVars.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) D:\devt\CplusPlus\Tests\ExportDLLVars\ExportDLLVars\VarsSource.c 1 1 ExportDLLVars

我使用向导创建了一个默认的 DLL 项目,并添加了以下两个源文件

#define NAME_SIZE 80
struct _Person
{
char name[NAME_SIZE];
int tel_nb;
int age;
};

#ifdef EXPORTDLLVARS_EXPORTS
#define DLL_VAR __declspec(dllexport)
#else
#define DLL_VAR __declspec(dllimport)
#endif

DLL_VAR int get_age();
DLL_VAR void set_age(int a);
DLL_VAR extern struct _Person ThePerson;

作为头文件VarsSource.h和C文件是这样的:

#include "VarsSource.h"
DLL_VAR struct _Person ThePerson;
DLL_VAR int get_age(){ return ThePerson.age; }
DLL_VAR void set_age(int a){ ThePerson.age = a; }

最佳答案

向导创建一个 C++ 项目。您的 C 文件无法与向导生成的 C++ 文件共享预编译头,这就是这部分错误的含义:或者预编译头是 C++,而您正在从 C 使用它

尝试以下操作:

  • 对所有配置进行全面清理。

  • 从项目中删除 stdafx.cpp 文件。

  • 重新检查项目设置,并确保配置属性/C/C++/预编译头文件已在项目级别关闭两者,每个单独的 C/C++ 文件。

关于c - VS 2013错误C1853尝试构建DLL(但不使用预编译头集),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35136678/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com