1
The compiler can even compile perfectly , but for some reason when I run the app.exe
gives me an error, 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 on 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
add a class outside the common header violates the link.
Add to the question the error you make when you run
app.exe
– Isac
I copied and executed your code here and it worked well, I did on Linux direct. I only had to take the
-static
of your compiler command.– gfleck
it seems that mingw requires libstdc++ to compile statically tbm in dll
– Rodrigo Santiago
For test purposes, compile the file
cpp
for.obj
and then put to compile together themain
, works?– Jefferson Quesado
no, of the same thing
– Rodrigo Santiago