I'm pretty new to C++, and here's my problem. I downloaded the g++ compiler on windows 10, and followed the vs code microsoft tutorial on how to set it up with vs code. In my main.cpp file, I include a #include "Line.h", which is a header file for a class. I also have a Line.cpp with constructor definition. However when building the main.cpp file using the built in vs code run command, I get an error: undefined reference to Line::Line(bla, bla, bla)... I did some research and found out that I have to explicitely tell the compiler to build the Line.cpp file, using the command: g++ main.cpp Line.cpp -o main. This seems like a really terrible solution, given that I might create many classes. Does that mean that I have to write a really long command, including each file that has to be compiled? I'm sure I'm missing something here... Is there a solution where I can just run "g++ main.cpp -o main" and it will link all the necessary files automatically?
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <sstream>
#include "Line.h"
using namespace std;
int main(int argc, char const *argv[])
{
    string ip;
    string port;
    string s=argv[1];
    if (s=="IP")
    {
        string tmp=argv[2];
        string::size_type p;
        if ((p=tmp.find(":"))!=string::npos)
        {
            ip=tmp.substr(0,p);
            tmp=tmp.substr(p);
            tmp.erase(tmp.begin());
            if (tmp.size()) port=tmp;
        }
        else
            ip=tmp;
        std::stringstream test("Game Time,0,150");
        std::string segment;
        std::vector<std::string> seglist;
        list<Line> lines;
        while(std::getline(test, segment, ','))
        {
            seglist.push_back(segment);
        }
        Line line(seglist[0], seglist[1], seglist[2]);
        lines.push_back(line);
    }
    /* code */
    return 0;
}
 
    