使用 Visual Studio 编译 SQLite C++ 2013 抛出 .c 文件的错误

Compiling SQLite with Visual Studio C++ 2013 Throws error for .c file

本文关键字:抛出 文件 错误 2013 C++ Visual Studio 编译 SQLite 使用      更新时间:2023-10-16

我已经将sqlite3.c文件添加到我的项目中。还有 #include。这是代码:

#include <sqlite3.h>
using namespace std;
int main()
{
    return 0;
}

我编译程序,它抛出以下错误:

1>..............librariessqlite-amalgamation-3080702sqlite3.c(15705): error C2440: '=' : cannot convert from 'void *' to 'char *'
1>          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..............librariessqlite-amalgamation-3080702sqlite3.c(19741): error C2440: '=' : cannot convert from 'void *' to 'sqlite3_mutex *'
1>          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..............librariessqlite-amalgamation-3080702sqlite3.c(20665): error C2440: '=' : cannot convert from 'void *' to 'char *'
1>          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..............librariessqlite-amalgamation-3080702sqlite3.c(20677): error C2440: '=' : cannot convert from 'void *' to 'char *'
1>          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..............librariessqlite-amalgamation-3080702sqlite3.c(21142): error C2440: '=' : cannot convert from 'void *' to 'char *'
1>          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..............librariessqlite-amalgamation-3080702sqlite3.c(21256): error C2440: '=' : cannot convert from 'void *' to 'char *'
1>          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>..............librariessqlite-amalgamation-3080702sqlite3.c(21411): error C2440: '=' : cannot convert from 'void *' to 'char *'

但是没有找到头或文件的错误。一切都找到了,错误只是在上面输出

我已经找到了解决方案。我将 C 代码编译为 C++,但更改它还不够。

我写给未来的访客:

首先,我必须更改文件的(仅文件)属性。右键单击该文件并选择属性,在C/C++下选择Advanced,然后选择Compile As并将其设置为 C(既不是默认值也不是C++)。

然后,您应该确保您的 .c 文件是在没有 clr 的情况下编译的。好吧,为此,在同一组C/C++菜单下,选择"Common Langugae Runtime Support"并将其设置为No Support....

我正在使用Visual Studio 17,我会添加它,找到"预编译头"的设置并将其设置为"不使用预编译头"。