我正在開發一個項目,因爲在2天內,在過去的2天裏,我剛剛搜索爲了使這個工作。我對C++相當陌生,而且我們的Class項目要求我們使用C++製作5個遊戲,並將它們導出到MySQL數據庫以獲得高分表。致命錯誤C1083:無法打開包含文件:'boost/variant.hpp':沒有這樣的文件或目錄
MySQL數據庫完全沒有問題。我唯一的問題是讓C++連接到MySQL數據庫。
所以這裏有一些更多的信息,有人可以幫助我。
我爲此使用Visual Studio 2010和2012。 (就像我在VS 2012中,雖然我的學校有2010年,所以我不知道這是否有任何兼容性差異,但我也有VS2010)。
我一直在尋找5個小時或更多的這類事情的網頁,比如爲什麼我的「的#include」語句也不會工作,我學到了進入項目屬性,添加不同的包括庫。上網一段時間後通常情況下,我可以找出我哪裏錯了,但在這裏,我只是打了一個死衚衕,作爲唯一的幫助,我可以說,這包括提升,這是我做了查找,但我完全陷入這一點。我的好友我做跟得不耐煩這類項目,因爲這是我們剩下要做的最後一件事。
所以這裏是我認爲我應該包括的東西。
我包括以下兩種情況的測試程序我做的(兩者是完全一樣的)
"Additional Include Directories"
C:\Users\Damian\Desktop\boost_1_53_0\boost_1_53_0\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include
我的鏈接 - >「附加庫目錄」
C:\Users\Damian\Desktop\boost_1_53_0\boost_1_53_0\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\lib\opt
C:\Program Files\MySQL\MySQL Server 5.6\lib
我的兩個節目,我的代碼試圖跑步。
這一個是一個,我在的Visual Studio 2012
#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 "username"
#define password "password"
#define database "db_test"
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;
}
測試這是我想要編譯上的Visual Studio 2010
#include <stdio.h>
#define W32_LEAN_AND_MEAN
#include <winsock2.h>
#include "mysql.h"
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <iostream>
// change these to suit your setup
#define TABLE_OF_INTEREST "highscores"
#define SERVER_NAME "127.0.0.1"
#define DB_USER "root"
#define DB_USERPASS "root"
#define DB_NAME "test"
// prototypes
void showTables(MYSQL*);
void showContents(MYSQL*,const char*);
using namespace std;
int main(int argc, char* argv[])
{
MYSQL *hnd=NULL; // mysql connection handle
const char *sinf=NULL; // mysql server information
hnd = mysql_init(NULL);
if (NULL == mysql_real_connect(hnd,SERVER_NAME,DB_USER,DB_USERPASS,DB_NAME,0,NULL,0))
{
fprintf(stderr,"Problem encountered connecting to the %s database on %s.\n",DB_NAME,SERVER_NAME);
}
else
{
fprintf(stdout,"Connected to the %s database on %s as user '%s'.\n",DB_NAME,SERVER_NAME,DB_USER);
sinf = mysql_get_server_info(hnd);
if (sinf != NULL)
{
fprintf(stdout,"Got server information: '%s'\n",sinf);
showTables(hnd);
showContents(hnd,TABLE_OF_INTEREST);
}
else
{
fprintf(stderr,"Failed to retrieve the server information string.\n");
}
mysql_close(hnd);
}
return 0;
}
void showTables(MYSQL *handle)
{
MYSQL_RES *result=NULL; // result of asking the database for a listing of its tables
MYSQL_ROW row; // one row from the result set
result = mysql_list_tables(handle,NULL);
row = mysql_fetch_row(result);
fprintf(stdout,"Tables found:\n\n");
while (row)
{
fprintf(stdout,"\t%s\n",row[0]);
row = mysql_fetch_row(result);
}
mysql_free_result(result);
fprintf(stdout,"\nEnd of tables\n");
return;
}
void showContents
(
MYSQL *handle,
const char *tbl
)
{
MYSQL_RES *res=NULL; // result of querying for all rows in table
MYSQL_ROW row; // one row returned
char sql[1024], // sql statement used to get all rows
commastr[2]; // to put commas in the output
int i,numf=0; // number of fields returned from the query
sprintf(sql,"select * from %s",tbl);
fprintf(stdout,"Using sql statement: '%s' to extract all rows from the specified table.\n",sql);
if (!mysql_query(handle,sql))
{
res = mysql_use_result(handle);
if (res)
{
numf = mysql_num_fields(res);
row = mysql_fetch_row(res);
fprintf(stdout,"Rows returned:\n\n");
while (row)
{
commastr[0]=commastr[1]=(char)NULL;
for (i=0;i<numf;i++)
{
if (row == NULL)
{
fprintf(stdout,"%sNULL",commastr);
}
else
{
fprintf(stdout,"%s%s",commastr,row);
}
commastr[0]=',';
}
fprintf(stdout,"\n");
row = mysql_fetch_row(res);
}
fprintf(stdout,"\nEnd of rows\n");
mysql_free_result(res);
}
else
{
fprintf(stderr,"Failed to use the result acquired!\n");
}
}
else
{
fprintf(stderr,"Failed to execute query. Ensure table is valid!\n");
}
return;
}
代碼現在這兩個給我此錯誤
1>c:\program files\mysql\mysql connector c++ 1.1.3\include\cppconn\connection.h(31): fatal error C1083: Cannot open include file: 'boost/variant.hpp': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
請幫忙!注:我只是試圖成功連接到數據庫,所以我可以運行不同的查詢和whatnot。這些程序只是我從別處複製的測試。
謝謝!
哇,感謝快這麼快的回覆!這解決了這個問題,但現在我得到了我的代碼的另一個問題。我將把它編輯成這個問題。或者是更好地使一個新的 – 2013-05-09 03:09:13
沒關係,我會離開它這樣,由於一噸的幫助!我現在要爲我的新問題提出一個新問題; \ – 2013-05-09 03:16:14