MYSQLサーバに接続するC言語でいくつかのコードを書いています。私はNetbeansを使用しており、これに新しい。私はそれを指示されたように設定し、MYSQLコネクタCをインストールしました。私はcygwinサイトからCYGWIN GCC、G ++、GDB、MAKEもインストールしました。私はcプロジェクトを作成し、プロパティ - >ビルド - > cコンパイラ - >インクルードディレクトリにmysqlコネクタ(C:\ Program Files \ MySQL \ Connector C 6.0.2 \ include)のパスを設定します。今、私はいくつかのエラーが発生すると、MYSQLサーバーとinterectにいくつかのコードを書く。ビルド後CおよびMYSQLアプリケーションの開発におけるビルドエラー
#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
int main(int argc, char** argv) {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "aaaa"; /* set me first */
char *database = "mysql";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
return (EXIT_SUCCESS);
}
エラー、次の発生します。
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:26: undefined reference to `_mysql_init'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:28: undefined reference to `_mysql_real_connect'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:30: undefined reference to `_mysql_error'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:34: undefined reference to `_mysql_query'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:35: undefined reference to `_mysql_error'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:38: undefined reference to `_mysql_use_result'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:41: undefined reference to `_mysql_fetch_row'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:44: undefined reference to `_mysql_free_result'
/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2/main.c:45: undefined reference to `_mysql_close'
make[2]: Leaving directory `/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2'
make[1]: Leaving directory `/cygdrive/c/Documents and Settings/AEM/My Documents/NetBeansProjects/CppApplication_2'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/cppapplication_2.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
私は多くのことをGoogleで検索しかし、この問題を解決するために何かを見つけることができませんでした。助けが必要。
これはリンカエラーです。 MySQLライブラリとリンクしていますか? –
@ Pileborg:HI、properties-> build-> linker->追加ライブラリディレクトリで、C:\ Program Files \ MySQL \ Connector C 6.0.2 \ lib \ optのパスを設定します。同じエラーが続く。 – user924888
さて、あなたはライブラリのある場所にパスを設定しましたが、実際のライブラリをどこかに追加しましたか? –