【问题标题】:What does the "sdl-config" mean when compiling sdl c program?编译 sdl c 程序时“sdl-config”是什么意思?
【发布时间】:2015-12-19 17:18:08
【问题描述】:

在许多教程中,我看到sdl-config 用于编译 sdl c 程序。在我也见过的 c++ 示例中。 这是来自here 的示例。

g++ sdlExample.cpp `sdl-config --cflags --libs` -o sdlExample

sdl-config --cflags --libs 是什么意思?为什么是内部重音?

【问题讨论】:

    标签: c++ c gcc compilation sdl


    【解决方案1】:

    在执行命令的 shell 中,反引号表示命令替换。因此,基本上,反引号内的任何内容都将作为命令执行,并替换其输出。

    例子:

    echo Today is `date`
    

    将首先执行date 命令,并替换它的输出。

    echo Today is Sat Dec 19 14:32:13 EST 2015
    

    然后执行产生:

    Today is Sat Dec 19 14:32:13 EST 2015
    

    所以,在你的指挥下,

    g++ sdlExample.cpp `sdl-config --cflags --libs` -o sdlExample
    

    shell 将首先执行,

    sdl-config --cflags --libs
    

    并替换它的输出,

    g++ sdlExample.cpp <output of the above command> -o sdlExample
    

    然后最后执行生成的命令行。

    要查看命令替换后实际执行了什么,只需在前面添加echo即可。

    echo g++ sdlExample.cpp `sdl-config --cflags --libs` -o sdlExample
    

    这将显示生成的命令行。

    请注意,命令替换也有另一种语法,当您有复杂的嵌套替换时,这是首选语法。

    echo g++ sdlExample.cpp $(sdl-config --cflags --libs) -o sdlExample
    

    这是一种非常标准的技术,可以为库/框架生成适当的命令行选项,其中选项取决于安装等。在这种情况下,sdl-config 命令生成必要的编译器选项(cflags 和 @987654334 @) 用于sdl 包。您可以通过直接在命令行上执行它来试验它还能做什么。

    sdl-config --cflags --libs
    

    sdl-config man page

    【讨论】:

      【解决方案2】:

      它只是输出适当的标志以传递给编译器,类似于 pkg-config 对其 .pc 文件(位于 /usr/lib/pkgconfig 中)所做的。

      【讨论】:

        猜你喜欢
        • 2017-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-25
        相关资源
        最近更新 更多