Linux环境下编译VS Code遇x11/xkbfile依赖检测失败求助
I’ve run into this exact issue before when building VS Code across different Linux distros, so let’s walk through targeted fixes based on your operating system:
First, Verify the Problem Source
First, confirm if pkg-config can actually locate the installed .pc files by running:
pkg-config --list-all | grep -E "(x11|xkbfile)"
If you get no output, the issue is definitely that your PKG_CONFIG_PATH isn’t pointing to the directory where these files live.
Fix for Ubuntu 18.04
On Ubuntu 18.04, the .pc files for libx11-dev and libxkbfile-dev are almost always in /usr/lib/x86_64-linux-gnu/pkgconfig/.
- Temporarily set the path to test if it works:
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH - Try running
yarnagain in your VS Code repo. If it succeeds, make the change permanent by adding the export to your user’s shell config (better than modifying/etc/profilefor system-wide changes):echo 'export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH' >> ~/.bashrc source ~/.bashrc
Fix for CentOS 7/8
CentOS stores 64-bit .pc files in /usr/lib64/pkgconfig/ instead.
- Temporarily apply the path:
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig/:$PKG_CONFIG_PATH - Test
yarnagain. If it works, save the setting permanently:echo 'export PKG_CONFIG_PATH=/usr/lib64/pkgconfig/:$PKG_CONFIG_PATH' >> ~/.bashrc source ~/.bashrc
If the Above Doesn’t Work
If pkg-config still can’t find the files, manually locate them first:
find /usr -name "x11.pc" find /usr -name "xkbfile.pc"
Take the directory path from the results (e.g., /usr/local/lib/pkgconfig/ if you installed from source) and add it to PKG_CONFIG_PATH instead.
Also, avoid running yarn with sudo unless absolutely necessary—sudo doesn’t inherit your user’s environment variables by default. If you must use sudo, use sudo -E yarn to preserve your PKG_CONFIG_PATH setting.
内容的提问来源于stack exchange,提问作者AGreenHand

