Author Topic: Can a console application return the FULL PATH for argv[0]?  (Read 5979 times)

Offline reb77

  • Single posting newcomer
  • *
  • Posts: 3
Can a console application return the FULL PATH for argv[0]?
« on: October 04, 2013, 11:13:29 pm »
Is there any way to configure Code::Blocks so that console applications return the FULL PATH for argv[0] instead of only returning the name of the program?  I am using the GNU GCC Compiler.  Thanks!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can a console application return the FULL PATH for argv[0]?
« Reply #1 on: October 04, 2013, 11:47:14 pm »
Prepend $(PROJECT_DIR) in Project -> Properties -> Build targets -> [target] -> Output filename

It worked for me, but there is a chance it won't work for you.
See here for details: http://wiki.codeblocks.org/index.php?title=Variable_expansion
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline reb77

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can a console application return the FULL PATH for argv[0]?
« Reply #2 on: October 05, 2013, 12:14:00 am »
The variable expansion suggestion is not quite what I'm looking for, but thanks for your quick reply anyway.

I am looking for a way for my program itself to know the exact path from where it was executed, even if the *.exe file is copied to a different location (such as when I give it to other users).  Other compilers that I have used (years ago) returned the full path for argv[0], but the GCC C compiler for Code::Blocks only returns the executable file name, not the full path, for argv[0].  I have been searching for a way of changing this, but have not yet found a way.


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Can a console application return the FULL PATH for argv[0]?
« Reply #3 on: October 05, 2013, 12:21:54 am »
This is a compiler specific question and not related to C::B itself.

Please reread the forum rules.
When registering here, you accepted to follow these rules.

There are several forums helping you with general programming question, in your case the gcc documentation, the gcc mailing list, probably stackoverflow.com  and your favourite search engine might be of help.

I lock this topic now, because it violates our forum rules.