使用Sqlite3库在MinGW Windows中

huangapple go评论57阅读模式
英文:

Using Sqlite3 Library in MinGW windows

问题

我正在开发一个CMake项目。我需要使用sqlite。

系统:Clion + MinGw-cmake + Windows 11

我尝试包含sqlite3.h。

#include <sqlite3.h>

会出现这样的错误:

致命错误:sqlite3.h:找不到文件或目录

在CMake中添加了sqlite3包。

find_package(SQLite3)

if(SQLITE3_FOUND)
    include_directories(${SQLITE3_INCLUDE_DIRS})
    target_link_libraries(tutorial ${SQLITE3_LIBRARIES})
endif(SQLITE3_FOUND)

无法找到SQLite3(缺少:SQLite3_INCLUDE_DIR SQLite3_LIBRARY)

最后,下载了 sqlite3.hsqlite3ext.h 并将它们放在项目目录中并包含了它。

#include "sqlite3.h"

现在出现了新的错误:

未定义的引用 sqlite3_open

请帮助我。

英文:

I'm developing a cmake project. I need to use sqlite.

System: Clion + MinGw-cmake + Windows 11

I tried to include sqlite3.h.

#include &lt;sqlite3.h&gt;

There will be error like this:

> fatal error: sqlite3.h: No such file or directory

Added sqlite3 package in cmake.

find_package (SQLite3)

if (SQLITE3_FOUND)
    include_directories(${SQLITE3_INCLUDE_DIRS})
    target_link_libraries (tutorial ${SQLITE3_LIBRARIES})
endif (SQLITE3_FOUND)

> Could NOT find SQLite3 (missing: SQLite3_INCLUDE_DIR SQLite3_LIBRARY)

Finally Downloaded sqlite3.h and sqlite3ext.h and placed them in project directory and included it.

#include &quot;sqlite3.h&quot;

Now there in new error:

> undefined reference to `sqlite3_open'

Please help me.

答案1

得分: 0

找到答案。

正如**@MarkBenningfield**在评论中所说。
> 从C或C++中使用SQLite的最简单方法是在你的源代码中包含"sqlite3.c"合并文件,并包含"sqlite3.h"头文件。(不需要"sqlite3ext.h")

你应该从这里下载zip文件,并将sqlite3.csqlite3.h提取到你的项目主路径。

然后在你的main.c文件头部包含sqlite3.h

#include "sqlite3.h"

最后,最重要的一步。将sqlite3.c添加到你的构建命令或你的CMakeLists.txt文件中:

add_executable(YourProjectName main.c sqlite3.c)

完成!

英文:

Found the answer.

Just as @MarkBenningfield said in comments.
> The simplest way to use SQLite from C or C++ is to include the "sqlite3.c" amalgamation in your source, and include "sqlite3.h". (You don't need "sqlite3ext.h")

You should download zip file from here and extract sqlite3.c and sqlite3.h to you project main path.

Then include sqlite3.h in the head of your main.c file:

#include &quot;sqlite3.h&quot;

The final and most important step. Add sqlite3.c to your build command or your CMAkeLists.txt file:

add_executable(YourProjectName main.c sqlite3.c)

Done!

huangapple
  • 本文由 发表于 2023年3月3日 21:34:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定