Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: ./

  1. #11
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: ./

    If you use GNU autotools, autoconf defines a variable called 'datarootdir' for the root directory under which data files are to be installed. By default $datarootdir is '/usr/local/share' and you'd be expected to concatenate that with your program name, e.g. to find files under '/usr/local/share/myprogram'.

    The automake manual suggests the following approach for pushing the variable into your program:

    Makefile.am
    Code:
    myprogram_CPPFLAGS = -DDATAROOTDIR=\"$(datarootdir)\"
    EDIT: To clarify, CPPFLAGS in this case is [C] [P]re[P]reprocessor, rather than [C] [P]lus [P]lus.

    You then get a macro called DATAROOTDIR in your program that you can use to find the resources. You'll probably have to write a little path search function to try that and then the current directory so that you can run the program without installing it.

    GNU autotools are quite intimidating when you first look at them but incredibly useful and will make packaging your application much easier when the time comes.

    http://en.wikipedia.org/wiki/GNU_build_system
    http://www.gnu.org/software/autoconf/#documentation
    http://www.gnu.org/software/automake...#documentation

    The automake manual has the best introduction to autotools within the GNU documentation but there are other tutorials around.
    Last edited by r-senior; February 24th, 2013 at 03:28 PM. Reason: Added note on CPPFLAGS

  2. #12
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: ./

    @OP: The posts by "r-senior", "dwhitney67" and others are already excellent.

    What they are missing a bit is some additional explanation: in Windows programs, it is quite common to have the data files of your application in sub-directories of the directory in which your program is located.

    In Linux, this is *not* a typical thing to do. Rather, as most software is installed using package managers, the path to look for data files is hardcoded into the binaries. Then, you don't ever need to look at the current path. As sometimes, you want to install your program to some special location (e.g., when you don't have root rights for installation), this data file location needs to be changed - If you designed your program to be compiled using autotools, they will handle that for you.

    Now some commercial software still uses the "Windows"-style approach that you also suggested. Such software is typically installed into the "/opt" branch of your filesystem. You can "find" your executable from the arguments to your program and compute the relative paths of your data files from there. Here is an example in c++:

    Code:
    #include <iostream>
    
    int main(int argc, char **args) {
        if (argc==0) {
            std::cerr << "Error: Can't find executable!" << std::endl;
            return 1;
        }
        std::cerr << "The executable is located at: " << args[0] << std::endl;
        return 0;
    }
    If you run it from a different directory than the executable is located, then that will be part of "args[0]".

  3. #13
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: ./

    Since I don't believe anyone's actually explained what libc is yet, it's the implementation of the C standard library.

    GNU libc has some extensions and useful features which you can utilise. I suggest you at least skim through the contents of www.gnu.org/software/libc/manual/html_mono/libc.html

  4. #14
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: ./

    Quote Originally Posted by thedardanius View Post

    My eninge needs to load texutres for its own font and GUI system. I want to get the right path to load textures. Currently, I manage by retrieving the dirdctory of the app itself and store it in a str. But when using ./, it would be far more easier, however I doubt if ./ is actually the directory of the app itself. If I e.g. launch if from shortcut, I dont know what the driectory would be.
    Don't do that.

    1. The "working directory" is for your user. This is where his/her files are, so that he an access them without having to specify paths. Don't use it for your own purposes.
    2. You have little control on that. If you application is started from a terminal, the current directory will be the current directory of the terminal session. And if you can change the current directory of your application to fix this, it means that your know where your files are, and you can also access them using an absolute path.

    The above advice is for both Linux and Windows. And on Linux the auxiliary files of an application have conventional locations (see other posts).

  5. #15
    Join Date
    May 2012
    Beans
    103

    Re: ./

    what a hell to switch! Its so difficult to realize everything is different....
    thanks you for all your help! I become more linux by the day...

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •