0

In my program I want to read file placed in specific sub directory of my repository.

I use relative path to do so. But the problem is that if I execute my binary file from other directory it obviously does not work. I also don't want to use absolute path, cause someone may install my repository in other place. Is there are any way to solve this problem using C++ or may be some through some setup script?

UPD: on linux

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
ralex
  • 23
  • 4
  • Which operating system(s) are you targeting? Unfortunately this fundamentally requires a platform specific solution. – Konrad Rudolph Feb 01 '23 at 10:20
  • This may be helpful for you. Add the -fPIC compilation option when compiling dynamic libraries, then generate position-independent code. – Liu-Feng Feb 01 '23 at 10:25
  • 2
    [Position-independent code](https://en.wikipedia.org/wiki/Position-independent_code) is about the address at which the machine code is placed within the memory, which has nothing to do with file accesses. – kotatsuyaki Feb 01 '23 at 11:32
  • Is accessing files using paths relative to the path to the binary acceptable? If so, see [Get path of executable](https://stackoverflow.com/questions/1528298/get-path-of-executable). – kotatsuyaki Feb 01 '23 at 11:41

0 Answers0