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

Include path #32

Open mottosso opened 4 years ago

mottosso commented 4 years ago

Hello!

I managed to get the example project in #30 running, after having fought with #31, but then ran into one more issue with the include path not seeming to be taken into account by blink.

Original Program

From #30.

#include <iostream>
#include <windows.h>

void changefunction() {
    static int n = 6;
    // n = 0;
    std::cout << n++ << std::endl;
}

int main(int argc, char** argv) {

    while (true)
    {
        changefunction();
        Sleep(1000);
    }

    return 0;

This builds fine, and changing anything in changefunction works well. But now look here.

Changed program

#include <iostream>
#include <windows.h>
#include "cannot_be_found.h"

void changefunction() {
...


The problem

There are two of them; one making the other harder to spot.

  1. blink does not report the error
  2. The error being that "cannot_be_found.h".. cannot be found

The error message is sporadic however, I suspect some issue with STDOUT and buffering. Here's what I typically see.

Detected modification to: C:\Users\marcus\source\repos\ConsoleApplication1\ConsoleApplication1.cpp
ConsoleApplication1.cpp

Finished compiling "C:\Users\marcus\source\repos\ConsoleApplication1\ConsoleApplication1.temp.obj" with code 2.

That empty space there appears related to whether or not there's an error. When compilation succeeds, the empty line is replaced with..

Successfully linked object file into executable image.


The workaround

I found that if I replicate my include path in the environment where blink is called, things appear to work.

$ set INCLUDE=all;the;things;VS;included
$ blink.exe consoleapplication1.exe
win!

Is there another way to cope with this? I couldn't find mention of this anywhere, but I don't see how blink could be used without it?

crosire commented 4 years ago

See https://github.com/crosire/blink/issues/31#issuecomment-629704515. Assuming this is using VC++ 2019, the include paths used to build your project won't be added to the command-line automatically, so this has to be done manually by modifying the line mentioned in the comment. This can probably be improved by trying to extract the include paths from the PDB (if VC++ 2019 stores them there). VC++ 2017 stored the entire command-line, hence why that was not necessary before.

mottosso commented 4 years ago

This can probably be improved by trying to extract the include paths from the PDB (if VC++ 2019 stores them there). VC++ 2017 stored the entire command-line, hence why that was not necessary before.

Aah, yes that makes sense. Thanks for confirming!