英文:
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.h
和 sqlite3ext.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 <sqlite3.h>
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 "sqlite3.h"
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.c
和sqlite3.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 "sqlite3.h"
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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论