我已经将VS代码设置为我的开发环境,并且使用了MSVC
构建工具(cl.exe
编译器)而不是g++
。我试图为我的环境设置SFML
。我想知道如何设置SFML
包含路径和库路径。此外,如何使用cl.exe
执行静态链接。注意:我只使用VS代码,而不使用Visual进行编程。下面是一些我用过的文件。Tasks.json
,Launch.json
,C_cpp_properties.json
。
Tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe",
"${workspaceFolder}\\*.cpp"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe - Build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\bin\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "C/C++: cl.exe build active file"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
发布于 2022-01-13 05:55:04
正如注释中提到的,您需要使用C++构建系统来管理依赖项和构建项目。VSCode没有像Visual那样提供任何内置的构建系统。
VSCode任务允许您指定命令行,然后可以在IDE中轻松调用该命令行。显示的任务只是一个“构建活动文件”任务,它只对没有依赖关系的简单程序非常有用。它对当前源文件调用cl.exe
(并传递一些其他参数)。
您可以通过在任务中添加"args“数组来指定包含目录并将参数传递给链接器,例如:
"/I", "D:\\Code Libraries\\boost_1_77_0",
"/link", "/LIBPATH:\"D:\\Code Libraries\\boost_1_77_0\\stage\\lib\"",
它假定boost标头和(静态构建的)库位于指定的位置。
您可能会通过添加带有VSCode任务的命令行来解决如何构建整个项目,但是使用构建系统可能更容易(即使该系统是CMake)。
https://stackoverflow.com/questions/70695086
复制