C++ 如何包含mysql标头?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2516187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:45:42  来源:igfitidea点击:

How to include the mysql header?

c++mysqlbuild

提问by symfony

I'm building an open source project from source,

我正在从源代码构建一个开源项目,

and it needs to include <mysql.h>:

它需要包括<mysql.h>

#if USE_MYSQL
#include <mysql.h>
#endif

and the compiler reports:

编译器报告:

mysql.h no such file or directory

MySQLis yet another great open source project. What do I need to do to make it work?

MySQL是另一个伟大的开源项目。我需要做什么才能让它发挥作用?

回答by mrk

For me, on Ubuntu 12.04, I needed to use this include

对我来说,在 Ubuntu 12.04 上,我需要使用这个包括

#include <mysql/mysql.h>

回答by KevenK

This will be entirely dependent on your build methods, whether that's using an IDE like Visual Studio, Eclipse, etc, or if you're using shell scripts and command lines in *nix.

这将完全取决于您的构建方法,无论是使用 Visual Studio、Eclipse 等 IDE,还是在 *nix 中使用 shell 脚本和命令行。

You will need to make sure that that file (mysql.h) exists in your 'includes' path.

您需要确保该文件 (mysql.h) 存在于您的“包含”路径中。

For example, in Visual Studio, you would go into:

例如,在 Visual Studio 中,您将进入:

Project Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories

项目属性 -> 配置属性 -> C/C++ -> 常规 -> 附加包含目录

And include the directory to which you have 'mysql.h' saved.

并包括您保存“mysql.h”的目录。

Then, for your linker properties, repeat the steps and include the respective DLL/LIB file path in your Additional Library Directories

然后,对于您的链接器属性,重复这些步骤并在您的附加库目录中包含相应的 DLL/LIB 文件路径

This will differ greatly depending on your environment, so more information would be needed for exact step-by-steps. But this should explain the actual Problem.

这将因您的环境而有很大差异,因此需要更多信息才能准确分步。但这应该可以解释实际的问题。

回答by proglammer

Did you try to give the include statement a full path to the file?

您是否尝试为 include 语句提供文件的完整路径?

回答by o15a3d4l11s2

#include  "path-spec"
#include  <path-spec>

Both syntax forms cause replacement of that directive by the entire contents of the specified include file. The difference between the two forms is the order in which the preprocessor searches for header files when the path is incompletely specified.

两种语法形式都会导致该指令被指定包含文件的全部内容替换。两种形式的区别在于当路径指定不完整​​时预处理器搜索头文件的顺序。

#include "path-spec"instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.

#include "path-spec"指示预处理器在包含 #include 语句的文件的同一目录中查找包含文件,然后在包含 (#include) 该文件的任何文件的目录中查找。然后预处理器沿着 /I 编译器选项指定的路径搜索,然后沿着 INCLUDE 环境变量指定的路径搜索。

#include <path-spec>instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then, when compiling from the command line, along the path specified by the INCLUDE environment variable.

#include <path-spec>指示预处理器首先沿 /I 编译器选项指定的路径搜索包含文件,然后在从命令行编译时沿 INCLUDE 环境变量指定的路径搜索。

I don't know what compiler you are using, but it may require you to add your includes and libs to the compilation:

我不知道您使用的是什么编译器,但它可能需要您将包含和库添加到编译中:

g++ bla.cpp -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient_r

回答by JazzCat

g++ -o Programname $(mysql_config --cflags) Programfile.cpp $(mysql_config --libs)

g++ -o 程序名 $(mysql_config --cflags) Programfile.cpp $(mysql_config --libs)

Does the trick in Linux.

在 Linux 中的技巧。