简体   繁体   English

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

[英]Cannot find the library in Eclipse for a C++ code to connect to MySQL

I am trying to run this code that I got from the internet, but I will get an error 我正在尝试运行从互联网获得的这段代码,但会收到错误消息

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

and

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

while building it. 在构建它时。 I am using Eclipse with MinGW to connect to MySQL. 我将Eclipse与MinGW结合使用以连接到MySQL。 I have added the: 我添加了:

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

to the include directory and 到包含目录和

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

to Library Directories (-L). 到图书馆目录(-L)。 Also I added the 我也添加了

libmysql.lib
mysqlcppconn-static.lib

to Additional Dependencies (-l). 到其他依赖项(-l)。

My code is: 我的代码是:

#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;
}

PS I'm new to this stuff PS我是新手

我必须从libmysql.lib的末尾删除.lib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM