1

I have a project that has more makefiles. At some specific folders, there are some makefiles that can create binaries/executables. I right-click on the makefile and do a Make Tarkgets -> Build -> all, so I get the executable right there. If I run the executable from console, it works fine, but if I do a right-click on it and Debug as -> Local C/C++ Application, it runs but at some point it is reading a file with relative path:

FILE *f = fopen(fName, "rb"); // fname is a relative path : ../../../path/to/file

if(f == NULL)
{
    perror(fName);
    exit(2);
}

and it is not finding it; the pointer is empty/NULL. To me it seems like Eclipse is searching for the file from the place where the project was opened, not from where the executable is. I suppose this because if I create a project from the makefile that created the executable, it works, it finds the file. But from that place I cannot see the sources, so, for placing breakpoints I have to run step-in by step-in until I get in the right place/right source.

Can anyone help me to fix this thing? Is there a way to make it search the file from the place where the executable is? Thanks

P.S. : I've seen this post, it's similar, but it did not pointed me to anything...

Community
  • 1
  • 1
sop
  • 3,445
  • 8
  • 41
  • 84

1 Answers1

2

I guess work directory is different for both cases, and thats why you can not open your file. Try to use absolute path for fopen() or look for a way to specify proper work directory for the second case.

There is a way to modify the working directory, as mentioned in this answer:

  • right-click on binary/executable Debug As -> Debug Configuration ...
  • in Arguments tab, in the bottom, there is a Working directory: area, uncheck the Use default and add the correct path (where is the executable/binary). The buttons Workspace... and File System... may help
Community
  • 1
  • 1
Sergio
  • 8,099
  • 2
  • 26
  • 52
  • Can you help me to "fix" it? I'd like to put it in the right place – sop Aug 11 '16 at 12:22
  • I cannot use absolute path because it will not work for other computers... – sop Aug 11 '16 at 12:24
  • So, is there a way to set the working directory? – sop Aug 11 '16 at 12:25
  • @sop Probably there should be some setting for debug session, that you start. You should refer to debugger docs. – Sergio Aug 11 '16 at 12:28
  • Thank you, I found the answer [here](http://stackoverflow.com/questions/329129/set-the-execution-directory-in-eclipse) – sop Aug 11 '16 at 12:28