[英]Having both C and C++ files in XCode project failing
I'm trying to use information from a sqlite database in my C++ project. 我正在尝试在我的C ++项目中使用来自sqlite数据库的信息。 I downloaded the sqlite amalgamation and added
sqlite3.h
and sqlite3.c
to my project, and added #include "sqlite3.h"
to my precompiled header file. 我下载了sqlite合并,并将
sqlite3.h
和sqlite3.c
添加到我的项目中,并将#include "sqlite3.h"
添加到了我的预编译头文件中。
However, Xcode no longer finds standard headers such as algorithm
, cassert
, cfloat
, etc. The specific error is this: 但是,Xcode不再找到标准标头,例如
algorithm
, cassert
, cfloat
等。具体错误是这样的:
Lexical or Preprocessor Issue - 'algorithm' file not found
If I remove the two sqlite files from the project, the headers can be found again. 如果我从项目中删除两个sqlite文件,则可以再次找到标头。 If I rename the
sqlite3.c
file to a .cpp
file, the headers are also found again. 如果将
sqlite3.c
文件重命名为.cpp
文件,则还会再次找到标头。 Removing #include "sqlite3.h"
does not change anything. 删除
#include "sqlite3.h"
不会更改任何内容。
However, I can't leave it as a .cpp
file because it gives errors since it uses some things that don't seem to be compatible with C++. 但是,我不能将其保留为
.cpp
文件,因为它会产生错误,因为它使用了某些似乎与C ++不兼容的东西。
Is there a way to have both C and C++ files in the same XCode project? 有没有办法在同一个XCode项目中同时包含C和C ++文件? (Or another way to include the sqlite library?)
(或包括sqlite库的另一种方法?)
To get things to work, I had to enclose my all of my #include
s with an #ifdef __cplusplus
and endif
. 为了使事情顺利进行,我必须用
#ifdef __cplusplus
和endif
封装我的所有#include
。 I don't quite know all of the mechanics behind why. 我不太了解为什么要使用所有机制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.