vscode 配置安装ege和easyx等第三方图形库失败

时间:2024-03-24 12:28:24

首先是下载ege和easyx图形库。

初步问题

对于ege图形库,把解压出来的graphics.h和libgraphics64.a库文件放进vscode的文件夹里,光这样是不行的。
vscode 配置安装ege和easyx等第三方图形库失败
仍然会提示找不到头文件。
要解决这个问题,必须了解vscode对于头文件的包含规则

Where are the include paths defined?
The include paths are defined in the “includePath” setting in a file called c_cpp_properties.json located in the .vscode directory in the opened folder.
You can create or open this file by either using the “C/Cpp: Edit Configurations” command in the command palette or by selecting “Edit “includePath” setting” in the lightbulb menu (see the screenshot below). The quickest way to locate a lightbulb is to scroll to the top of the source file and click on any green squiggle that shows up under a #include statement.

include 路径是怎么被定义的?
它是在 c_cpp_properties.json 文件里设定的,修改方法:
vscode 配置安装ege和easyx等第三方图形库失败
${workspaceFolder} 意味着当前打开的文件夹。
因为我这里已经把一堆头文件放进当前目录了,所以c_cpp_properties.json无需修改。

When a folder is opened, the extension attempts to locate your system headers based on your operating system, but it does not know about any other libraries that your project depends on. You can hover over the green squiggles or open the Problems window to understand which headers the IntelliSense engine is unable to open - sometimes it’s the dependent headers that can’t be located.

打开文件夹时,扩展试图定位你的系统头文件基于你的操作系统。但是它不知道你的项目依赖的任何其他库。你可以在绿色悬停界面上打开问题窗口,去了解智能提示无法打开哪些。

还需要修改tasks.json文件,主要是修改args部分:

{
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}.exe"
        "-I","${workspaceFolder}",
        "-L","${workspaceFolder}",
        "-l","libgraphics64",
        ],    // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }

-I(大写i)表示头文件目录,-L表示库文件目录,-l(小写L)表示库文件。
这里有个坑,gcc或者g++连接库的时候,库名字要删去前缀lib和后缀。
对于ege来说,libgraphics64.a就是静态库文件,写进去要变成“graphics64”,否则它找不到会出错。

vscode 配置安装ege和easyx等第三方图形库失败
为什么出错了?

进一步查询资料:
库有两种:静态库(.a、.lib)和动态库(.so、.dll)。
window上对应的是.lib、.dll。
linux上对应的是.a、.so

刚才的库文件是.a结尾,它难道不是windows需要的?
找一找vc

vscode 配置安装ege和easyx等第三方图形库失败
几个库都尝试了不行,修改文件:

{
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}.exe"
        "-I","${workspaceFolder}",
        "-L","${workspaceFolder}",
        "-l","graphics64",
        "-l","uuid",
        "-l","msimg32",
        "-l","gdi32",
        "-l","imm32",
        "-l","ole32",
        "-l","oleaut32",
        
        ],    // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

vscode 配置安装ege和easyx等第三方图形库失败

问题待解决…………