【工具使用】clang++踩坑记录

问题解决过程

起源是学习Makefile时,尝试编译一直编译不起来
相关代码👉在这里
make是一只报错找不到库:
在这里插入图片描述
这里用clang++编译,尝试用g++编译,能够通过,排除没有iostream的问题
考虑是否为Makefile的问题,尝试用clang++直接编译CPP文件,依然不通过,考虑为clang++配置的问题
这就需要考虑进行vscode 的一些配置了,操作后的配置文件在后面附上(不一定通用,在当前状态运行通过)
最后由tasks.json给的提示,给clang++指定一个参数:“–target=x86_64-w64-mingw”
尝试直接在CPP文件上操作,通过
那么将这条参数修改到Makefile中,这里注意不能直接加到$(CXX) -o $@ $(objects)里面,需要再定义一个CXXFLAGS:CXXFLAGS := --target=x86_64-w64-windows-gnu
通过!~~
在这里插入图片描述

附录:配置文件

  • c_cpp_properties.json
    //c_cpp_properties.json
    {
        "configurations": [
            {
                "name": "g++",
                "intelliSenseMode": "clang-x64",
                "compilerPath": "D:/ProgramFiles/LLVM/bin/g++.exe",
                "includePath": [
                    "${workspaceFolder}"
                ],
                "defines": [],
                "browse": {
                    "path": [
                        "${workspaceFolder}"
                    ],
                    "limitSymbolsToIncludedHeaders": true,
                    "databaseFilename": ""
                },
                "cStandard": "c11",
                "cppStandard": "c++17"
            }
        ],
        "version": 4
    }
    
  • tasks.json
    	// tasks.json
    {
        "version": "2.0.0",
        "command": "clang++", // 要使用的编译器
        "args": [ // 编译命令参数
            "${file}", //要编译的文件名,你也可以改成 *.cpp 表示编译当前目录所有的cpp文件
            "-o", //指定生成的程序名字
            "${file}.exe", //这是你要生成的程序名字
            "-Wall", // 开启额外警告
            "-g", // 生成和调试有关的信息
            "-static-libgcc", // 静态链接
            "-fcolor-diagnostics", //彩色信息
            "-w", //屏蔽警告
            "--target=x86_64-w64-mingw", // 默认target为msvc,不加这一条就会找不到头文件
            //以下都是链接库参数,需要链接什么库就加在这
            "-lws2_32",
            "-lIphlpapi",
            "-lgdi32"
        ],
        "tasks": [
            {
                "label": "clang++", // 任务名称,与launch.json的preLaunchTask相对应
                "type": "shell",
                "group": {
                    "kind": "build",
                    "isDefault": true // 设为false可做到一个tasks.json配置多个编译指令,需要自己修改本文件,我这里不多提
                },
                "presentation": {
                    "echo": true,
                    "reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never。具体参见VSC的文档
                    "focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译c和c++来说,设为true没有意义
                    "panel": "shared" // 不同的文件的编译信息共享一个终端面板
                }
            }
        ],
        "problemMatcher": {
            "owner": "c",
            "fileLocation": [
                "relative",
                "${workspaceRoot}"
            ],
            "pattern": {
                "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "severity": 4,
                "message": 5
            }
        }
    }
    
  • launch.json
    // launch.json
    {
        // 使用 IntelliSense 了解相关属性。 
        // 悬停以查看现有属性的描述。
        // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
                "type": "cppdbg", // 配置类型,这里只能为cppdbg
                "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
                "program": "${file}.exe", // 将要进行调试的程序的路径
                "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
                "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,我一般设置为true
                "cwd": "${workspaceRoot}", // 调试程序时的工作目录
                "targetArchitecture": "x86_64", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
                "externalConsole": true,
                "internalConsoleOptions": "neverOpen",
                "MIMode": "gdb", //调试器名称
                "miDebuggerPath": "D:\\ProgramFiles\\LLVM\\bin\\gdb.exe", //调试器路径
                "preLaunchTask": "clang++", //和tasks.json的label值要相同
                "setupCommands": [
                    {
                        "description": "为 gdb 启用整齐打印",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }
    
  • settings.json
    // settings.json
    {
        "files.defaultLanguage": "cpp", // ctrl+N新建文件后默认的语言
        "editor.formatOnType": true, // 输入时就进行格式化,默认触发字符较少,分号可以触发
        "editor.snippetSuggestions": "top", // snippets代码优先显示补全
        "code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入
        "code-runner.executorMap": {
            "c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics -lws2_32 -liphlpapi -lgdi32 -w --target=x86_64-w64-mingw && $dir$fileNameWithoutExt",
            "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics -lws2_32 -liphlpapi -lgdi32 -w --target=x86_64-w64-mingw && $dir$fileNameWithoutExt"
        }, // 设置code runner的命令行,点击右上角的运行跑的就是这些代码,里面的参数啥意思看tasks.json
        "code-runner.saveFileBeforeRun": true, // run code前保存
        "code-runner.preserveFocus": true, // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false
        "code-runner.clearPreviousOutput": true, // 每次run code前清空属于code runner的终端消息
        "C_Cpp.clang_format_sortIncludes": false, // 格式化时调整include的顺序(按字母排序),这个别开,不信以后遇到问题你就会来关了
        "C_Cpp.intelliSenseEngine": "Default", // 可以为Default或Tag Parser,后者较老,功能较简单。具体差别参考cpptools扩展文档
        "C_Cpp.errorSquiggles": "Disabled", // 因为有clang的lint,所以关掉
        "C_Cpp.autocomplete": "Disabled", // 因为有clang的补全,所以关掉
        "clang.completion.enable": true,
        "C_Cpp.dimInactiveRegions": false,
        "clang.cflags": [ // 控制c语言静态检测的参数
            "--target=x86_64-w64-mingw",
            "-std=c11",
            "-Wall"
        ],
        "clang.cxxflags": [ // 控制c++静态检测时的参数
            "--target=x86_64-w64-mingw",
            "-std=c++17",
            "-Wall"
        ],
        "files.associations": {
            "ostream": "cpp",
            "iostream": "cpp",
            "array": "cpp",
            "atomic": "cpp",
            "*.tcc": "cpp",
            "cctype": "cpp",
            "clocale": "cpp",
            "cmath": "cpp",
            "cstdarg": "cpp",
            "cstddef": "cpp",
            "cstdint": "cpp",
            "cstdio": "cpp",
            "cstdlib": "cpp",
            "cstring": "cpp",
            "cwchar": "cpp",
            "cwctype": "cpp",
            "deque": "cpp",
            "unordered_map": "cpp",
            "vector": "cpp",
            "exception": "cpp",
            "algorithm": "cpp",
            "memory": "cpp",
            "memory_resource": "cpp",
            "optional": "cpp",
            "string": "cpp",
            "string_view": "cpp",
            "system_error": "cpp",
            "tuple": "cpp",
            "type_traits": "cpp",
            "utility": "cpp",
            "fstream": "cpp",
            "initializer_list": "cpp",
            "iosfwd": "cpp",
            "istream": "cpp",
            "limits": "cpp",
            "new": "cpp",
            "sstream": "cpp",
            "stdexcept": "cpp",
            "streambuf": "cpp",
            "typeinfo": "cpp",
            "chrono": "cpp",
            "thread": "cpp",
            "winsock2.h": "c",
            "ws2tcpip.h": "c",
            "windows.h": "c",
            "stdio.h": "c",
            "ctime": "cpp",
            "iomanip": "cpp"
        } // 效果效果比cpptools要好
    }
    
在Kali中使用Clang是完全可行的。 Clang完全支持交叉编译作为其设计的固有部分,具体取决于您的Clang版本的配置方式,它可能支持许多交叉编译器,也可能仅支持本机目标。您可以使用"-target <architecture>"选项来指定要为其构建的体系结构。如果需要了解给定目标支持的处理器列表,可以使用"--print-supported-cpus"选项来打印出来。此外,您还可以使用"-march=<cpu>"选项来指定Clang应该为特定处理器家族成员和更高版本生成代码。所以,使用Clang来编译代码是一种可行的选择。 关于Clang的诊断选项,它们可以控制Clang打印诊断信息(如错误和警告)的方式。例如,"-fshow-column"选项可以显示列号,"-fshow-source-location"选项可以显示源代码位置,"-fcaret-diagnostics"选项可以以插入符号形式显示诊断信息等。详细信息可以在Clang用户手册中找到。 至于aes-finder,它是一个在运行时用于查找AES密钥的实用程序。它可以在运行进程内存中查找128、192和256位的AES密钥。您可以在Visual Studio 2013中打开aes-finder.sln解决方案,或者使用gcc/clang编译器来使用它。 总结起来,Kali可以使用Clang进行编译,并且您可以通过设置目标体系结构和使用适当的选项来自定义编译过程。另外,您还可以使用aes-finder实用程序来查找AES密钥。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [最新kali之clang](https://blog.csdn.net/qq_40399982/article/details/112328869)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [aes-finder, 在运行过程中,用于查找AES密钥的实用程序.zip](https://download.csdn.net/download/weixin_38744270/11770394)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值