C++ Portable way of programmatically finding the executable root directory <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c">how to find the location of the executable in C</a> </p> </blockquote> <p>Hi,</p> <p>I am looking for a portable way to find the root directory of a program (in C++). For instance, under Linux, a user could copy code to /opt, add it to the PATH, then execute it:</p> <pre><code>cp -r my_special_code /opt/ export PATH=${PATH}:/opt/my_special_code/ cd /home/tony/ execution_of_my_special_code </code></pre> <p>(where "execute_my_special_code" is the program in /opt/my_special_code).</p> <p>Now, as a developer of "execution_of_my_special_code", is there a portable programmatical way of finding out that the executable is in /opt/my_special_code?</p> <p>A second example is on MS Windows: What if my current working directory is on one hard drive (e.g. "C:\") and the executable is placed on another (e.g. "D:\")?</p> <p>Ultimately, the goal is to read some predefined configuration files that are packaged with the program code without forcing the user to enter the installation directory.</p> <p>Thanks a lot in advance!</p>