Есть 3 файла, упростил чтобы понять что не так, но в итоге так и не понял.
test.cpp :
#include <iostream>
#include "A.h"
// #include "A.cpp"
using namespace std;
int main(){
A a(5);
cout<<a.i;
getchar();
}
A.h:
#ifndef A_H
#define A_H
#include <iostream>
using namespace std;
class A
{
public:
int i;
A(int x);
~A();
};
#endif
A.cpp:
#include "A.h"
A::A(int x):i(x)
{
}
A::~A()
{
}
Почему main.cpp компилируется лишь при строчке #include "A.cpp" ??
При вводе: gcc test.cpp
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.text+0x20): undefined reference to `A::A(int)'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.text+0x31): undefined reference to `std::ostream::operator<<(int)'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.text+0x42): undefined reference to `A::~A()'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.text+0x58): undefined reference to `A::~A()'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.text+0x7e): undefined reference to `std::ios_base::Init::~Init()'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.text+0xae): undefined reference to `std::ios_base::Init::Init()'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.xdata+0xc): undefined reference to `__gxx_personality_seh0'
c:/users/user/documents/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\cc0vfGWh.o:test.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
collect2.exe: error: ld returned 1 exit status