microsoft / microsoft/vscode-cpptools
Enable support for switching between different output targets with compile_commands.json
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 6.2k
- Forks
- 1.7k
- Ø Merge
- 14 Std. 46 Min.
- Gemergte PRs (30 T.)
- 61
Beschreibung
Hi @sean-mcmanus
Here is a minimal example of this scenario
main.cpp
#include <iostream>
void func1()
{
#ifdef TARGET_1
std::cout << "Target 1" << std::endl;
#elif defined(TARGET_2)
std::cout << "Target 2" << std::endl;
#else
std::cout << "Other" << std::endl;
#endif
}
int main()
{
func1();
return 0;
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
"compileCommands": ".vscode/compile_commands.json"
}
],
"version": 4
}
compile_commands.json
[
{
"file": "/home/karim/test/main.cpp",
"directory": "/home/karim/test/build",
"arguments": [
"g++",
"-c",
"-o",
"b.o",
"-DTARGET_2",
"/home/karim/test/main.cpp"
],
"output": "/home/karim/test/build/b.o"
},
{
"file": "/home/karim/test/main.cpp",
"directory": "/home/karim/test/build",
"arguments": [
"g++",
"-c",
"-o",
"a.o",
"-DTARGET_1",
"/home/karim/test/main.cpp"
],
"output": "/home/karim/test/build/a.o"
}
]
Note that "output" field is used to distinguish between different processing modes (output file) of the same source file as documented by the Json Compilation Database Specification


Originally posted by @KarimAshraf1995 in https://github.com/microsoft/vscode-cpptools/discussions/10408#discussioncomment-4893606
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit nachzuverfolgen, wie Einträge aus compile_commands.json für eine Quelldatei ausgewählt werden, und verwende dabei die beiden Einträge für main.cpp und ihre output-Felder als Verhaltensbeispiel. Prüfe, wie c_cpp_properties.json die Kompilierungsdatenbank mit IntelliSense verbindet. Als erledigt gilt die Aufgabe, wenn die Erweiterung zwischen den Verarbeitungsmodi TARGET_1 und TARGET_2 unterscheiden und wechseln kann, anstatt einen Befehl als kanonisch zu behandeln.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp, vscode
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100