首页 > 解决方案 > 链接 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;
}

标签: c++windowseclipsesqlitemingw-w64

解决方案


推荐阅读