[英]How do I manually import .h files into the system library?
I have some C code that #include
s the file <mysql/mysql.h>
. 我有一些
#include
s文件<mysql/mysql.h>
C代码。 I am running on a Mac, and cannot figure out how to get mysql
installed (after running the solution found on SO, the mysql
directory does not even exist in the system library). 我在Mac上运行,无法弄清楚如何安装
mysql
(运行在SO上找到的解决方案后,系统目录中甚至没有mysql
目录)。 I was able to download MySQL from the source code, and now I have a mysql.h
file-- in the "include" directory of the source code. 我能够从源代码下载MySQL,现在我在源代码的“ include”目录中有一个
mysql.h
文件。
However, moving this file into the system library alone will obviously not make my program work. 但是,仅将此文件移入系统库显然不会使我的程序正常工作。 I expect that I need to compile the library (which I've done), and to move the binary file somewhere, in order to be linkable to my program.
我希望我需要编译该库(已经完成),并将二进制文件移动到某个位置,以便可链接到我的程序。
As per @RustyX's suggestion, I installed the Mac MySQL package. 按照@RustyX的建议,我安装了Mac MySQL软件包。 That put a copy of
mysql.h
into the /usr/local/mysql-5.7.19-macos10.12-x86_64/include/
directory. 这样就将
mysql.h
的副本放入/usr/local/mysql-5.7.19-macos10.12-x86_64/include/
目录。 However: 然而:
1) I am using gcc
to compile the .c file. 1)我正在使用
gcc
来编译.c文件。 I am not sure how to configure gcc
to include the directory in question. 我不确定如何将
gcc
配置为包含相关目录。 I tried -L(directory path)
-- both for the installed Mac MySQL package, and the MySQL source code I downloaded-- but I get the following error: 我尝试了
-L(directory path)
-既适用于已安装的Mac MySQL软件包,也适用于我下载的MySQL源代码-但出现以下错误:
ld: library not found for -lmysqlclient
Is there another path I would include for mysqlclient
? 有没有我要为
mysqlclient
提供的其他路径? Or another package to install? 还是要安装其他软件包?
2) Even if I do include it, it will still not find the file since the called-for filename is <mysql/mysql.h>
, and the filename it will find is <include/mysql.h>
. 2)即使我确实包含它,由于调用的文件名是
<mysql/mysql.h>
,并且找到的文件名是<include/mysql.h>
,它仍然找不到文件。 Since the file is used by others, is the best course of action here to rename the include
directory to mysql
? 由于该文件被其他人使用,因此最好的做法是将
include
目录重命名为mysql
吗? Or to change the path in the .c file, and then change it back every time before committing? 还是要更改.c文件中的路径,然后在提交之前每次都将其更改回?
Have you tried a statement like this, 您是否尝试过这样的声明,
#include <mysql.h> //in your program
To compile and run 编译运行
gcc -w -c -g -I/usr/include/mysql filename.c
gcc -o filename filename.o -L/usr/lib64/mysql -lmysqlclient
./filename (input params)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.