Using relative path in symbolic link executable

I am trying to figure out how to use my link app in ubuntu. I compiled the code and contains relative paths to specific files. When I create a link to an executable file in another directory, I cannot use these paths. Is there a way (in my code or in link building) that it works with relative paths?

thank

+4
source share
1 answer

This realpath, after what? Something like this (source for testin the following example):

#include <iostream>
#include <cstdlib>

int main(int argc, char *argv[])
{
        char *path = realpath(argv[0], NULL);
        std::cout << path << '\n';
        free(path);
        return 0;
}

Execution Example:

$ ln -s tmp/test
$ ./test
/home/mlil/tmp/test
$
0
source

Source: https://habr.com/ru/post/1678989/


All Articles