【问题标题】:compiling a c++ program including mysql编译一个包含mysql的c++程序
【发布时间】:2010-05-06 03:37:43
【问题描述】:

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

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

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

谢谢

【问题讨论】:

    标签: c++ mysql gcc


    【解决方案1】:

    -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 文件。

    【讨论】:

    • 如果我没记错的话,其中一些只有在 LD_LIBRARY_PATH 、 PATH 等环境宏未设置或设置为与您预期不同的路径时才需要。
    • 他使用-lmysqlclient也是错误,他应该改写-llibmysqlclient.a吗?
    • @bobobobo:不。链接器将lib 添加到开头,将.a 添加到末尾。
    • Just noting I had a hell of a nightmare earlier 我的系统上没有.a 文件
    【解决方案2】:

    请尝试“man g++”以完整说明各种选项的含义。

    【讨论】:

      【解决方案3】:

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-30
        • 2014-11-15
        • 2014-06-03
        • 2012-03-27
        相关资源
        最近更新 更多