Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:03:05+00:00 2026-05-26T14:03:05+00:00

Possible Duplicate: Get path of executable I’m programming on Windows using MinGW, gcc 4.4.3.

  • 0

Possible Duplicate:
Get path of executable

I’m programming on Windows using MinGW, gcc 4.4.3. When I use the main function like this:

int main(int argc, char* argv[]){
    cout << "path is " << argv[0] << endl;
}

On Windows I get a full path like this: “C:/dev/stuff/bin/Test”. When I run the same application on Linux, however, I get some sort of relative path: “bin/Test”. It’s breaking my application! Any idea on how to make sure the path is absolute on both systems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:03:06+00:00Added an answer on May 26, 2026 at 2:03 pm

    No, there isn’t. Under most shells on Linux, argv[0] contains exactly what the user typed to run the binary. This allows binaries to do different things depending on what the user types.

    For example, a program with several different command-line commands may install the binary once, and then hard-link the various different commands to the same binary. For example, on my system:

    $ ls -l /usr/bin/git*
    -rwxr-xr-x  109 root  wheel  2500640 16 May 18:44 /usr/bin/git
    -rwxr-xr-x    2 root  wheel   121453 16 May 18:43 /usr/bin/git-cvsserver
    -rwxr-xr-x  109 root  wheel  2500640 16 May 18:44 /usr/bin/git-receive-pack
    -rwxr-xr-x    2 root  wheel  1021264 16 May 18:44 /usr/bin/git-shell
    -rwxr-xr-x  109 root  wheel  2500640 16 May 18:44 /usr/bin/git-upload-archive
    -rwxr-xr-x    2 root  wheel  1042560 16 May 18:44 /usr/bin/git-upload-pack
    -rwxr-xr-x    1 root  wheel   323897 16 May 18:43 /usr/bin/gitk
    

    Notice how some of these files have exactly the same size. More investigation reveals:

    $ stat /usr/bin/git
    234881026 459240 -rwxr-xr-x 109 root wheel 0 2500640 "Oct 29 08:51:50 2011" "May 16 18:44:05 2011" "Jul 26 20:28:29 2011" "May 16 18:44:05 2011" 4096 4888 0 /usr/bin/git
    $ stat /usr/bin/git-receive-pack 
    234881026 459240 -rwxr-xr-x 109 root wheel 0 2500640 "Oct 29 08:51:50 2011" "May 16 18:44:05 2011" "Jul 26 20:28:29 2011" "May 16 18:44:05 2011" 4096 4888 0 /usr/bin/git-receive-pack
    

    The inode number (459240) is identical and so these are two links to the same file on disk. When run, the binary uses the contents of argv[0] to determine which function to execute. You can see this (sort of) in the code for Git’s main().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to get the application executable name in Windows (C++ Win32 or
Possible Duplicate: How to get current python interpreter path from inside a Python script?
Possible Duplicate: Passing varible types though mod-rewrite howdy, I'm using the get method on
Possible Duplicate: Get the Files inside a directory Is there a function that can
Possible Duplicate: Get connecting IP from specified ports that using by other program. If
Possible Duplicate: How do I get this CSS text-decoration issue to work? I'm using
Possible Duplicate: How to programmatically get DLL dependencies On Windows, in a C++ program,
Possible Duplicate: Get a function's arity Say I have: function a(x) {}; function b(x,y)
Possible Duplicate: Full path from file input using jQuery I have the following html
Possible Duplicate: How can I get the application's path in .NET in a console

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.