Код: Выделить всё
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
i затем установил build-essential , которая вытащила копию GCC-13 и g ++-13 через apt .
Компиляторы по умолчанию в системе - GCC версия 13.
Код: Выделить всё
$ gcc --version
Version 13...
$ g++ --version
Version 13...
Должен ли я изменить файл cmakelist.txt? Br /> Обратите внимание, что окончательная сборка выполняется внутри контейнера Docker, а версия компилятора по умолчанию внутри контейнера - версия 14. Вот почему сценарий командной строки достигает успеха, но Linter VS Code считает, что есть ошибки PATH . < /p>
Мне пришлось сделать целую кучу вещей, чтобы заставить это работать. < /p>
Во -первых, в настройках. json : Примечание: потому что я делаю удаленную разработку через ssh , мне нужно было изменить удаленную версию настроек. />
Код: Выделить всё
{
"cmake.configureSettings": {
"CMAKE_C_COMPILER": "/usr/bin/gcc-14",
"CMAKE_CXX_COMPILER": "/usr/bin/g++",
"CMAKE_BUILD_TYPE": "Debug"
}
}
Код: Выделить всё
{
"version": 3,
"configurePresets": [
{
"name": "remote gcc",
"displayName": "Remote gcc",
"description": "Use Remote GCC toolchain",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_C_COMPILER": "/usr/bin/gcc-14",
"CMAKE_CXX_COMPILER": "/usr/bin/g++-14",
"CMAKE_BUILD_TYPE": "Debug"
}
}
],
"buildPresets": [
{
"name": "remote-gcc",
"configurePreset": "remote-gcc"
}
]
}
Код: Выделить всё
cat build/CMakeCache.txt | grep -i compiler
< /code>
# example output...
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++
CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc
< /code>
You can also inspect View->Output, and select CMake from the dropdown. Look for log messages which show which compiler is used.
Thirdly, in my Dockerfile
Код: Выделить всё
cmake -DCMAKE_CXX_COMPILER=/path/to/g++
< /code>
Technically, this is seperate to the VS Code & Intellisense issue, but it may be worth knowing about.
Fourth, you may need to delete the build cache. (Output directory.)
You can do it manually or with CTRL+SHIFT+P
"configurations": [
{
"name": "Remote GCC",
"compilerPath": "/usr/bin/g++-14",
"cppStandard": "c++23",
"intelliSenseMode": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "gnu17"
}
],
"version": 4
}
< /code>
Open Command Pelette
- Search for "C/C++: Edit Configurations (UI)".
- Set:
- IntelliSense Mode → "linux-gcc-x64"
- Compiler Path → "/usr/bin/g++-14"
- C++ Standard → "c++23"
- Save and restart VS Code.
Подробнее здесь: https://stackoverflow.com/questions/793 ... in-vs-code