Cześć
Mam problem z działaniem Visual Studio Code pod C++ dla kilku plików (.h i .cpp) w przypadku, gdy np. deklaruję klasę w pliku strin1.h, a następnie w main.cpp jest on dołączany za pomocą #include.
Przy kliknięciu "biuld active file" (CTRL+SHIFT+B) wyskakują mi na terminalu poniższe komunikaty:
Trwa uruchamianie kompilacji...
C:\MinGW\bin\g++.exe -g "D:\Programowanie\C++\C-plus-plus-Prata\12. 4 12.5 12.6 String Class 2.0/*.cpp" -o "D:\Programowanie\C++\C-plus-plus-Prata\12. 4 12.5 12.6 String Class 2.0\main.exe"
g++.exe: error: D:\Programowanie\C++\C-plus-plus-Prata\12. 4 12.5 12.6 String Class 2.0/*.cpp: Invalid argument
g++.exe: fatal error: no input files
compilation terminated.
Kompilacja została zakończona z błędami.
The terminal process failed to launch (exit code: -1).
Terminal will be reused by tasks, press any key to close it.
A przy kliknięciu "Run Code" (CTRL+ALT+N) dostaje wprost informację o undefined reference do poszczególnych metod klasy:
[Running] cd "d:\Programowanie\C++\C-plus-plus-Prata\12. 4 12.5 12.6 String Class 2.0\" && g++ main.cpp -o main && "d:\Programowanie\C++\C-plus-plus-Prata\12. 4 12.5 12.6 String Class 2.0\"main
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x22): undefined reference to `String::String()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x49): undefined reference to `operator>>(std::istream&, String&)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x5c): undefined reference to `operator<<(std::ostream&, String const&)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0xa2): undefined reference to `String::String()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x173): undefined reference to `String::operator=(char const*)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x1f1): undefined reference to `operator<<(std::ostream&, String const&)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x27c): undefined reference to `operator<(String const&, String const&)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x2b8): undefined reference to `operator<<(std::ostream&, String const&)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x2f5): undefined reference to `operator<<(std::ostream&, String const&)'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x30b): undefined reference to `String::HowMany()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x392): undefined reference to `String::~String()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x39e): undefined reference to `String::~String()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x3c3): undefined reference to `String::~String()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x3e2): undefined reference to `String::~String()'
C:\Users\Win10\AppData\Local\Temp\ccjE9yvr.o:main.cpp:(.text+0x3f4): undefined reference to `String::~String()'
collect2.exe: error: ld returned 1 exit status
[Done] exited with code=1 in 0.624 seconds
Path w zmiennych systemowych ma między innymi ustawioną ścieżkę na MinGW\bin.
Podejrzewam, że problem tkwi w plikach .vscode (launch.json, task.json i settings.json), ponieważ skorzystałem z ich starej konfiguracji na moim ostatnim urządzeniu i zmieniłem do nich tylko ścieżki na obecne MinGW\bin
C:\MinGW\bin
.
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": "g++.exe - Kompiluj i debuguj aktywny plik",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "\\usr\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Włącz formatowanie kodu dla gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
settings.json
{
"files.associations": {
"iostream": "cpp",
"cmath": "cpp",
"ostream": "cpp",
"atomic": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: \"C:\\MinGW\\bin\\g++.exe\""
}
],
"version": "2.0.0"
}
Z góry dziękuję za wszelką pomoc, bo już naprawdę nie mam pomysłu co może być nie tak oprócz nieprawidłowego fragmentu kodu w powyższych plikach. :/