编译包含mysql的c ++程序

时间:2010-05-06 03:37:44

标签: c++ mysql gcc

我是gcc的新手,并尝试使用以下命令编译包含mysql.h的c ++程序:

g ++ -o test test.cpp -L / usr / include / mysql -lmysqlclient -I / usr / include / mysql

它没有问题,但我想知道是否有人可以向我解释这些论点。我不喜欢使用我不理解的命令。

由于

3 个答案:

答案 0 :(得分:4)

-o test表示输出文件名为“test”。

test.cpp当然是你的源文件。

-L/usr/include/mysql意味着在/ usr / include / mysql以及通常的链接路径中查找库。 (可能在这里找不到任何库;我的libmysqlclient.a位于标准库目录/ usr / lib中。所以我认为你不需要这个选项。)

-lmysqlclient表示链接mysqlclient库(实际上名为libmysqlclient.a)

-I/usr/include/mysql意味着在/ usr / include / mysql以及通常的包含路径中查找#include文件。

答案 1 :(得分:1)

尝试使用“man g ++”来全面描述各种选项的含义。

答案 2 :(得分:0)

man gcc会为您提供所有这些选项的详细信息。

g ++ -o test test.cpp -L / usr / include / mysql -lmysqlclient -I / usr / include / mysql

g++ : the compiler
-o test : name the resulting binary "test" 
test.cpp : your source file
-L : the directory to look in for libraries (that are specified by -l)
-l : named library to link against (looks for it in -L)
-I : the directory to look in for #included header files
相关问题