WSL下使用mysql编译C程序
我是 WSL 新手,我在上次 C 编译上花费了很多时间。 我有一个小型 C 程序,它使用 WSL 进行编译和执行(在 CLion 开发环境中,使用 CMake 进行编译和链接),
#include <stdio.h>
int main()
{
char server[16] = "localhost"; char username[16] = "root";
char password[16] = ""; char database[16] = "sports";
char *conn = NULL;
if (conn == NULL) {
printf("MySQL: initialisation de %s a echouee", database);
return 1;
}
}
然后我尝试添加一些数据库功能;最小的一个是连接到数据库
#include "include/mysql.h"
#include <stdio.h>
int main()
{
char server[16] = "localhost"; char username[16] = "root";
char password[16] = ""; char database[16] = "sports";
MYSQL* conn = mysql_init(NULL);
if (conn == NULL) {
printf("MySQL: initialisation de %s a echouee", database);
return 1;
}
}
这里,我需要获取 mysql 环境并链接到 lib。我的参考是: 指向 MYSQL C Api 文档的链接 我的理解是我需要将我的代码与 libmysqlclient.a 链接。但是,我找不到图书馆。我已经完成了:
sudo apt update
sudo apt install mysql-server
但是,我无法找到 mysql 库和包含文件并了解如何链接它。我已经尝试过:
find_package(MYSQL REQUIRED)
在Cmake文件中,但没有成功。 欢迎任何帮助、建议、指点。
I'm newbie with WSL and there is a lot of time spent from my last C compilation.
I have a small C program which compile and execute with WSL (in the CLion dev environment, which use CMake to compile and link)
#include <stdio.h>
int main()
{
char server[16] = "localhost"; char username[16] = "root";
char password[16] = ""; char database[16] = "sports";
char *conn = NULL;
if (conn == NULL) {
printf("MySQL: initialisation de %s a echouee", database);
return 1;
}
}
then i'm trying to add some database functionalities; a minimal one is connecting to the database
#include "include/mysql.h"
#include <stdio.h>
int main()
{
char server[16] = "localhost"; char username[16] = "root";
char password[16] = ""; char database[16] = "sports";
MYSQL* conn = mysql_init(NULL);
if (conn == NULL) {
printf("MySQL: initialisation de %s a echouee", database);
return 1;
}
}
Here, I need to get the mysql environment and to link to the lib. My reference is:
Link to the MYSQL C Api doc
My understanding is that I need to link my code with libmysqlclient.a. But, I'm not able to find the library. I've done:
sudo apt update
sudo apt install mysql-server
But then, I'm not able to find the mysql library and and include(s) file(s) and to understand how to link it. I've tried:
find_package(MYSQL REQUIRED)
in the Cmake file, but without success.
Any helps, advices, pointers are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论