gpt4 book ai didi

mysql - 为什么编译器找不到 mysql 包含?

转载 作者:行者123 更新时间:2023-11-29 22:38:55 25 4
gpt4 key购买 nike

每当我尝试使用 mysql include 编译文件时,我都会收到错误,我对 mysql 进行的所有调用都出现“ undefined reference ”。我在我的包含中包含了该库,并且我相信我正在按照我应该的方式包含它。我不知道到底发生了什么事。

这是我正在尝试的测试文件:

#include <mysql/mysql.h>
#include <stdio.h>
#include <stdlib.h>


int main(void) {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "????";
char *pass = "????";
char *db = "TEST_DB";

conn = mysql_init(NULL);

if(!mysql_real_connect(conn, server, user, pass, db, 0, NULL, 0))
fprintf(stderr, "%s\n", mysql_error(conn));
if(!mysql_query(conn, "show tables"))
fprintf(stderr, "%s\n", mysql_error(conn));

res = mysql_use_result(conn);
printf("MySQL Tables in mysql DB: \n");

while((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);

mysql_free_result(res);
mysql_close(conn);
return 0;
}

这是我正在尝试的简单编译器命令,以及操作的输出:

clang test.c -o driver

铿锵输出:

clang version 3.6.0 (tags/RELEASE_360/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2
Found candidate GCC installation: /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.9.2
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2
Candidate multilib: .;@m64
Selected multilib: .;@m64

"/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o driver /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/crtbegin.o -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2 -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/ellipsis/test-47b79a.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/crtend.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64/crtn.o

/tmp/ellipsis/test-47b79a.o: In function `main':
test.c:(.text+0x4f): undefined reference to `mysql_init'
test.c:(.text+0x8d): undefined reference to `mysql_real_connect'
test.c:(.text+0xb1): undefined reference to `mysql_error'
test.c:(.text+0xdf): undefined reference to `mysql_query'
test.c:(.text+0x102): undefined reference to `mysql_error'
test.c:(.text+0x126): undefined reference to `mysql_use_result'
test.c:(.text+0x147): undefined reference to `mysql_fetch_row'
test.c:(.text+0x180): undefined reference to `mysql_free_result'
test.c:(.text+0x189): undefined reference to `mysql_close'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

C mysql 库存在于“/usr/include/mysql/”中

最佳答案

尝试clang test.c -o driver -lmysqlclient也许?#include 指令仅供编译器了解如何使用该库。您需要将二进制文件包含在您的编译中。

关于mysql - 为什么编译器找不到 mysql 包含?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29441159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com