Problem description while I am trying to move my code from Linux to Windows:
- MinGW on Windows linker problems
- happens when I am calling a user-defined class inside my Main.cpp ( works fine if I do not call the user-defined class constructor in Main )
Relevant code samples:
Person.hpp
class Person
{
public:
Person(const string& iName,
const list<string>& iContactDetails,
);
virtual ~Person();
...
Main.cpp
#include "Person.hpp"
...
int main()
{
...
Person myPerson = Person (myName, myContactDetails); //here is the linker problem
...
return 0;
}
Compilation command:
standalone
g++ -o MyProgram.exe Main.cpp -Wall
Makefile (tried even CC instead of CXX, or LDFLAGS=-lgdi32 instead of CXXFLAGS)
EXECUTABLE = MyProgram.exe
CXX = "C:\MinGW\bin\g++.exe"
CXXFLAGS = -Wall // tried LDFLAGS=-lgdi32 as well
src = $(wildcard *.cpp)
obj = $(src:.cpp=.o)
all: myprog
myprog: $(obj)
$(CXX) -o $(EXECUTABLE) $^ $(CXXFLAGS)
.PHONY: clean
clean:
del $(obj) $(EXECUTABLE)
Error:
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\....:Main.cpp:(.text+0x124c): undefined reference to `Person::~Person()'
collect2.exe: error: ld returned 1 exit status
As a summary, I encounter Linker problems during the MinGW G++ compilation step:
All external entity references are resolved. Library components are linked to satisfy external references to entities not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment.
I tried to follow other similar problems, but they are unfortunately different issues:
- C compiler error: undefined reference to function
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- facing error in linking codes in c++
How should I change my Makefile or my code? What flags does MinGW uses in Windows? Thank you very much