简体   繁体   中英

How can I use `pkg-config` with clangd?

I have started writing a GTK App in C, and since I am using clangd as my language server, I want to configure it. The problem is, clangd won't listen when I pass this as my compiler flags:

CompileFlags:
        Add: [ $(pkg-config --cflags gtk4) ],
        Remove: [ ],
        Compiler: clang

I need to fix this if I want to make any use of the language server, so what do I do? (I use VSCode)

The .clangd config file does not support executing commands via $(command) .

The recommended way to configure a project for use with clangd is to generate a compile_commands.json file based on your project's build metadata.

A simple way to do this is using bear . For example, if your project is built using make , you can run bear make and bear will generate a compile_commands.json file based on the compiler commands that make invoked.

For more sophisticated build systems, the build system may itself provide a way to generate a compile_commands.json file (for example, CMake has DCMAKE_EXPORT_COMPILE_COMMANDS=ON ).

For more details, see https://clangd.llvm.org/installation#project-setup .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM