C++ 为c+配置VSCode+;linux中的开发人员
main.cpp:C++ 为c+配置VSCode+;linux中的开发人员,c++,visual-studio-code,C++,Visual Studio Code,main.cpp: #include <X11/Xlib.h> #include <unistd.h> int main() { Display *display = XOpenDisplay(0); return 0; } 帮助我配置VSCode plz upd: 合作 "tasks": [ { "label": "linux64", "type": "shell", "command": "g
#include <X11/Xlib.h>
#include <unistd.h>
int main()
{
Display *display = XOpenDisplay(0);
return 0;
}
帮助我配置VSCode plz
upd:合作
"tasks": [
{
"label": "linux64",
"type": "shell",
"command": "g++-8",
"args": [
"${workspaceFolder}/Sources/main.cpp",
"-L",
"/usr/include/X11/",
"-lX11",
"-o",
"HW"
],
"group": {
"kind": "build",
"isDefault": true,
}
}
]
VSCode提示#包括X11/Xlib.h,所以我想他知道在哪里可以找到库
不,没有
未定义的引用是链接错误。编译代码时,必须使用-l
选项指定X11库,并使用-l
选项指定其位置。例如
g++main.cpp-lX11library-L/path/to/X11/lib
您缺少要链接的库,例如-lX11
(这是小L),您可能需要-L/path/to/X11/lib
来提供库搜索路径。XOpenDisplay
XOpenDisplay`的未定义引用是一个链接器错误,它告诉您链接器无法找到函数XOpenDisplay
的定义位置,因为编译器在标题中找到了声明。我建议您在Windows上安装Linux子系统。我最近发现了它,它对我帮助很大。@PeMaCN尽量避免建议别人安装额外的软件以另一种方式解决问题。这个问题问的是一个简单的编译问题,而不是其他软件能做得更好。无论安装什么软件,都会存在完全相同的问题。一个更合适的建议是打开开发者命令提示符,学习如何从命令行使用外部库进行编译和链接——这样你就可以告诉VS你想要它做什么。你还必须通过在编译字符串中包含-lLibrary
来告诉链接器要链接哪个库。ooops,错过了
"tasks": [
{
"label": "linux64",
"type": "shell",
"command": "g++-8",
"args": [
"${workspaceFolder}/Sources/main.cpp",
"-L",
"/usr/include/X11/",
"-lX11",
"-o",
"HW"
],
"group": {
"kind": "build",
"isDefault": true,
}
}
]