c++ - 在 Eclipse 中找不到用于连接 MySQL 的 C++ 代码的库

标签 c++ eclipse dll static-libraries mysql-connector

我正在尝试运行我从互联网上获得的这段代码,但我会得到一个错误

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql.lib' 

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lmysqlcppconn-static.lib

在构建它的时候。我正在使用带有 MinGW 的 Eclipse 连接到 MySQL。 我添加了:

C:\Program Files\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include

到包含目录和

C:\Program Files\MySQL\MySQL Server 5.6\lib
C:\Program Files\MySQL\Connector C++ 1.1.2\lib\opt

到库目录 (-L)。我还添加了

libmysql.lib
mysqlcppconn-static.lib

附加依赖项 (-l)。

我的代码是:

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

#include <stdlib.h>
#include <Windows.h>
#include <mysql.h>
#include "mysql_connection.h"

#include <cppconn/driver.h>
#define host "localhost"
#define username "root"
#define password "root"
#define database "tests"

int main()
{
    MYSQL* conn;
    conn = mysql_init( NULL );
    if( conn )
    {
        mysql_real_connect( conn, host, username, password, database, 0, NULL, 0 );
    }
    MYSQL_RES* res_set;
    MYSQL_ROW row;
    unsigned int i;
    mysql_query( conn, "SELECT * FROM tbl_clients WHERE id = 1" );
    res_set = mysql_store_result( conn );
    unsigned int numrows = mysql_num_rows( res_set );
    if( numrows )
    {
        row = mysql_fetch_row( res_set );
        if( row != NULL )
        {
            cout << "Client ID  : " << row[0] << endl;
            cout << "Client Name: " << row[1] << endl;
        }
    }
    if( res_set )
    {
        mysql_free_result( res_set );
    }
    if( conn )
    {
        mysql_close( conn );
    }

    return 0;
}

附言我是新手

最佳答案

我不得不从 libmysql.lib 的末尾删除 .lib

关于c++ - 在 Eclipse 中找不到用于连接 MySQL 的 C++ 代码的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17264601/

相关文章:

c++ - 无法定义我自己的运算符......

c++ - SQLite - Windows 平台的首选编码

Python,使用 ctypes 创建 C++ 类包装器

visual-studio-2008 - 线程 'Win32 Thread'已退出,代码为-1073740777(0xc0000417)

c++ - 如何解决以下错误?

c++ - 如何在 long long int 中使用加法?

java - 如何跨工作区保存 E​​clipse 启动配置文件?

c++ - 跨平台 C++ 项目入门

eclipse - 如何为扩展 FormEditor 类的编辑器启用“保存”和“另存为”操作

c++ - 将现有的 C++ 项目编译为 DLL