c++ - 链接 sqlite3 库的 Eclipse 问题
问题描述
安装了https://www.mingw-w64.org/并添加了库,但仍然出现此错误:
Info: Internal Builder is used for build
g++ -std=c++11 -O3 -Wall -c -fmessage-length=0 -o main.o "..\\main.cpp"
g++ -std=c++11 "-LF:\\MinGW\\lib" -o test.exe main.o -lpsapi -lpthread -lm -ldl
main.o:main.cpp:(.text.startup+0x1f): undefined reference to `sqlite3_open'
main.o:main.cpp:(.text.startup+0x36): undefined reference to `sqlite3_errmsg'
f:/mingw/bin/../lib/gcc/i686-w64-mingw32/4.8.3/../../../../i686-w64-mingw32/bin/ld.exe: main.o: bad reloc address 0x36 in section `.text.startup'
collect2.exe: error: ld returned 1 exit status
使用安装程序并选择“Native Windows”+“i686”。
编码:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
#include <sqlite3.h>
sqlite3 *db;
int main() {
int open = sqlite3_open("test.db", &db);
if( open ) {
cerr << "Can't open database: " << sqlite3_errmsg(db) << endl;
sqlite3_close(db);
exit(1);
}
return 0;
}
解决方案
推荐阅读
- python - 具有嵌套和属性查找的字典?
- node.js - TypeError:无法读取未定义的属性“电子邮件”,如何解决
- teamcity - 我的新 Megatester 构建 (1215.7) 项目没有被 EyeOfSauron 选中
- arrays - 返回其视图控制器时刷新自定义表视图
- javascript - 重命名反应钩子属性的好习惯?
- c++ - 为什么“使用命名空间标准;” 在 C++ 中处理双精度时给出不同的结果?
- r - 带有 if 语句的嵌套 for 循环
- typescript - Sonarqube - 删除这个对变量“x”的无用赋值
- python - Django Queryset 模拟对象和计数
- python - 使用 django-filter 使用嵌套序列化程序过滤视图