我正在尝试使用 C API 连接到 mariaDB https://downloads.mariadb.org/client-native/1.0.0/ 我在 Windows 8 上使用 Code::Blocks 12.11 编译和编写代码。
- 我已将包含 .h 文件的文件夹放在 D:\Programmering\biblotek\C\mariaDB-API\include
- 以及包含 .lib 文件的文件夹在 D:\Programmering\biblotek\C\mariaDB-API\lib
所以:
\include has all the .h files
\lib has all the .lib files
链接:我已完成以下链接库:
-在 Settings --> Compiler.. --> Search directories --> Compiler 链接\include 文件夹
-在 Settings --> Compiler.. --> Search directories --> Linker 链接\lib 文件夹
-在设置-->编译器..-->链接器设置
中链接libmariadb.lib暂停...
-在 Project 中链接 \include 文件夹 --> Build Options... --> 搜索目录 --> Compiler
-在 Project 中链接 \lib 文件夹 --> Build Options... --> 搜索目录 --> Linker
-在 Project --> Build Options... --> Linker Settings
中链接 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 和谷歌,但没有找到适合我的东西,所以我决定详细发布我做错了什么。
关于如何使用 C 连接到 mariaDB 有什么想法吗? (如何使这个程序工作)
亲切的问候!
Tip of the life time of earth: Don't get Windows 8.
最佳答案
链接完整路径 D:\Programmering\biblotek\C\mariaDB-API\lib\libmariadb.lib 在 Project --> Build Options... --> Linker Settings.
我不确定链接器“搜索目录”是否工作,我无法让它们工作
或者,您可以使用 CMake 生成 Code::Blocks 项目
关于c - mariadb c api windows undefined reference to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14879524/