The compiler even compiles perfectly, but for some reason when I run app.exe
it returns an error, it follows my code:
main.cpp
#include <iostream>
#include "cpp.h"
int main() {
ClassA * a = new ClassA();
std::cout << "Versao : " << a->version() << std::endl;
delete a;
return 0;
}
cpp.h
#ifndef HEADER
#define HEADER
class ClassA {
public:
int val;
ClassA ();
int version();
};
#endif
cpp.cpp
#include "cpp.h"
class ClassB {
public:
int val;
ClassB() {
val = 15;
}
};
ClassA::ClassA() {
ClassB * b = new ClassB();
val = b->val;
delete b;
}
int ClassA::version() {
return val;
}
I compile in mingw-64
using the following commands:
g++ -shared -fpic cpp.cpp -o cpp.dll
g++ -static -static-libstdc++ -static-libgcc main.cpp cpp.dll -o app.exe
The app.exe
when executed shows an error "The application could not be initialized correctly (0xc000007b)". If I remove ClassB
, and put the value in val
directly it works normally, which made me think that
adding a class outside the common header violates the link.