【发布时间】:2013-01-30 12:46:20
【问题描述】:
我正在尝试使用 C API https://downloads.mariadb.org/client-native/1.0.0/ 连接到 mariaDB 我在 Windows 8 上,正在使用 Code::Blocks 12.11 来编译和编写代码。
- 我已将包含 .h 文件的文件夹放入 D:\Programmering\biblotek\C\mariaDB-API\include
- 以及 D:\Programmering\biblotek\C\mariaDB-API\lib 中带有 .lib 文件的文件夹
所以:
\include has all the .h files
\lib has all the .lib files
链接:我已执行以下操作来链接库:
-在 Settings --> Compiler.. --> 搜索目录 --> Compiler
中链接了 \include 文件夹>-在 Settings --> Compiler.. --> 搜索目录 --> Linker
中链接 \lib 文件夹>-在 Settings --> Compiler.. --> Linker Settings
中链接 libmariadb.lib暂停...
-项目中的\include文件夹-->构建选项...-->搜索目录-->编译器
-项目中的\lib 文件夹 --> 构建选项... --> 搜索目录 --> Linker
-在 项目 --> 构建选项... --> 链接器设置
中链接 libmariadb.lib在Project --> Build Option...我选择了编译器"GNU GCC Compiler"。
编译器标志:-g
这是代码:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <C:\MinaProgram\Libs\sqlclientC\include\mysql.h>
#include <my_global.h>
#include <mysql.h>
int main(void) {
MYSQL mysql;
MYSQL_ROW row;
const char *aQuery = "SELECT * from livedata";
if(mysql_library_init(0, NULL, NULL)) { //Initiera bibliotek
fprintf(stderr, "could not initialize MySQL library\n");
exit(1);
}
printf("AH!\n");
MYSQL mysql;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"localhost","root","ooops","firsttest",0,NULL,0)) { //Anslut till databas, error meddelande om fel.
fprintf(stderr, "Failed to connect to server!\n");
}
/*GO CODE*/
if(!mysql_real_query(&mysql, aQuery, strlen(aQuery))) {
fprintf(stderr, "Query error, kinda'\n");
}
//mysql_fetch_row()
/*CLOSURE */
mysql_close(&mysql);
mysql_library_end();
return EXIT_SUCCESS;
}
我编译,这是构建日志中的响应:
||=== test, Release ===|
obj\Release\main.o:main.c:(.text.startup+0x32)||undefined reference to `mysql_library_init'|
obj\Release\main.o:main.c:(.text.startup+0x54)||undefined reference to `mysql_init@4'|
obj\Release\main.o:main.c:(.text.startup+0x95)||undefined reference to `mysql_real_connect@32'|
obj\Release\main.o:main.c:(.text.startup+0xb4)||undefined reference to `mysql_real_query@12'|
obj\Release\main.o:main.c:(.text.startup+0xeb)||undefined reference to `mysql_close@4'|
obj\Release\main.o:main.c:(.text.startup+0xf1)||undefined reference to `mysql_library_end'|
||=== Build finished: 6 errors, 0 warnings (0 minutes, 3 seconds) ===|
我搜索了 stackoverflow 和 google 并没有发现任何适合我的东西,所以我决定详细发布我做错了什么。
任何想法如何使用 C 连接到 mariaDB? (如何使这个 porgram 工作)
亲切的问候!
地球生命周期的提示:不要安装 Windows 8。
【问题讨论】:
-
这看起来像是一个链接器错误。请问什么是构建(链接)命令?
-
我只使用 Build --> Build (Ctrl + F9)。我没有像我发布的那样在代码块中更改任何链接,例如链接。我实际上并不知道链接命令。这是一面旗帜还是我错过了什么?
标签: c api windows-8 codeblocks undefined-reference