<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## pkg-config pkg-config 是一個幫助在編譯和鏈接程序時管理庫路徑和編譯器標志的工具。它主要用于自動檢索庫的路徑和編譯選項,而不需要手動指定。 pkg-config 默認系統默認位置 ``` /usr/lib/pkgconfig /usr/share/pkgconfig /usr/local/lib/pkgconfig /usr/local/share/pkgconfig ``` ## 語法 ``` --version output version of pkg-config --modversion output version for package --atleast-pkgconfig-version=VERSION require given version of pkg-config --libs output all linker flags --static output linker flags for static linking --short-errors print short errors --libs-only-l output -l flags --libs-only-other output other libs (e.g. -pthread) --libs-only-L output -L flags --cflags output all pre-processor and compiler flags --cflags-only-I output -I flags --cflags-only-other output cflags not covered by the cflags-only-I option --variable=NAME get the value of variable named NAME --define-variable=NAME=VALUE set variable NAME to VALUE --exists return 0 if the module(s) exist --print-variables output list of variables defined by the module --uninstalled return 0 if the uninstalled version of one or more module(s) or their dependencies will be used --atleast-version=VERSION return 0 if the module is at least version VERSION --exact-version=VERSION return 0 if the module is at exactly version VERSION --max-version=VERSION return 0 if the module is at no newer than version VERSION --list-all list all known packages --debug show verbose debug information --print-errors show verbose information about missing or conflicting packages,default if --cflags or --libs given on the command line --silence-errors be silent about errors (default unless --cflags or --libsgiven on the command line) --errors-to-stdout print errors from --print-errors to stdout not stderr --print-provides print which packages the package provides --print-requires print which packages the package requires --print-requires-private print which packages the package requires for static linking ``` ### --modversion 查看版本 ``` > pkg-config --modversion json 0.11 ``` ### --variable 查找pkg-config 所在位置 ``` pkg-config --variable pc_path pkg-config ``` ### --list-all 查看系統中的所有庫 ``` > pkg-config --list-all libffi libffi - Library supporting Foreign Function Interfaces libselinux libselinux - SELinux utility library tic tic - ncurses 5.9 add-on library libmongoc-ssl-1.0 libmongoc-1.0 - SSL support for the libmongoc-1.0 library. ncurses ncurses - ncurses 5.9 library com_err com_err - Common error description library json json-c - JSON implementation in C, compat shim. Use json-c instead. ... ``` ### --libs/--cflags ``` // 查看庫所在位置 > pkg-config --libs json -L/lib64 -ljson-c // 查看頭文件所在位置 > pkg-config --cflags json -I/include -I/include/json-c ``` > 依賴編譯時候同時使用 `--libs --cflags` 即可自動輸出庫所在位置和頭文件所在位置 ## 示例 ### 引用 linux 中的 json 庫 vim json.cpp ``` #include <json.h> #include <stdio.h> int main() { struct json_object *jobj; char *str = "{ \"hello\": \"word\" }"; printf("str:\n---\n%s\n---\n\n", str); jobj = json_tokener_parse(str); printf("jobj from str:\n---\n%s\n---\n", json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY)); return 0; } ``` 編譯 ``` > g++ -o json json.cpp `pkg-config --libs --cflags json > ./json str: --- { "hello": "word" } --- jobj from str: --- { "hello": "word" } --- ``` ### 創建 pkg-config 項目 假設項目位置位于 /root 下 ``` mymath --mymath.pc --include/ --mymath.h --src/ --mymath.cpp --lib/ --libmymath.a # 庫文件 ``` mymath.pc ``` # mymath.pc librootdir=/root/mymath Name: mymath Description: a simple add function Version: 1.0 Cflags: -I${librootdir}/include Libs: -L${librootdir}/lib -lmymath ``` include/mymath.h ``` namespace mymath { int add(int a, int b); }; ``` src/mymath.cpp ``` #include "mymath.h" #include <iostream> namespace mymath { int add(int a, int b) { std::cout << "Add " << a << " and " << b << " is " << a + b << std::endl; return a + b; } }; ``` 編譯 ``` > cd mymath > g++ -o mymath.o -c src/mymath.cpp -Iinclude > ar rcs lib/libmymath.a mymath.o ``` 創建一個引用 次項目的項目 test.cpp ``` #include "mymath.h" int main(int argc, char** argv) { mymath::add(1, 2); return 0; } ``` 編譯 ``` // 通過 PKG_CONFIG_PATH 變量指定 or 也可以放到系統默認位置中 // cp /root/mymath/mymath.pc /usr/share/pkgconfig/ > export PKG_CONFIG_PATH=/root/mymath/ > g++ -o test test.cpp `pkg-config --cflags --libs mymath` > ./test Add 1 and 2 is 3 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看