crosire / blink

A tool which allows you to edit source code of any MSVC C++ project live at runtime
BSD 2-Clause "Simplified" License
1.09k stars 81 forks source link

Linker issues #34

Closed Pombal closed 3 years ago

Pombal commented 3 years ago

Hi, I'm aware that blink isn't supposed to work when changing the data layout of structs/classes but I have a question related to linking:

If a program has been compiled and linked with a struct such as

struct test
{
    int i;
};

and then blink is used to change it to

struct test
{
    int i;
    float f;
};

Then blink may not find some symbols such as: Unresolved external symbol '_fltused' or if we try to std::cout the new float member: Unresolved external symbol '__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z'

My question is why can't blink find these symbols in the object file? Are these symbols only emitted at linking time?

And how can blink be changed to fix this kind of issue?

Thanks.

crosire commented 3 years ago

Blink doesn't handle the case where a change adds a new dependency. The problem here is that the CRT is seemingly split up into many small libs, one of which defines all the floating-point exports. Since your original app did not make use of that, it was not linked into the app. After the change it is now referenced though, and would need to be added in addition to the change itself. You should be able to workaround this problem by linking against the CRT statically though (/MT or /MTd).

Pombal commented 3 years ago

Thanks, that's helpful. Appreciate the quick reply.