Author Topic: Indefinite Paths in Compiler Installation Directory  (Read 3749 times)

Offline joat

  • Single posting newcomer
  • *
  • Posts: 5
Indefinite Paths in Compiler Installation Directory
« on: July 19, 2006, 07:59:20 pm »
Is there any way to use indefinite paths for the compiler's installation directory setting? I tried using ./MinGW  but that didn't work. I'm wondering because I put MinGW's folder inside my codeblocks folder. The reasoning behind this is that I would like to set up a portable copy of CB with MinGW. What I basically want is a version of CB and MinGW inside a self-extracting 7-zip archive. That way I can just put it on my flash drive and run it to extract it to whatever computer I'm using. I can then just open up the project files on my flash drive and work on them. Once I'm finished working I can just save everything and delete the folder that was created by extracting the archive. I need indefinite paths because the path to MinGW will be different depending on the username since I usually extract to the desktop. I do realize that I could just make two separate archives and have the MinGW one extract to C:\MinGW, but that just wouldn't be as much fun :)
By the way, awesome project you guys got going here.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Indefinite Paths in Compiler Installation Directory
« Reply #1 on: July 19, 2006, 08:55:59 pm »
Is there any way to use indefinite paths for the compiler's installation directory setting?
You can use global variables for the drive. Thus you would only have to change one global variable (the drive letter) and you can run C::B from a memory stick. How is this?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Indefinite Paths in Compiler Installation Directory
« Reply #2 on: July 19, 2006, 08:59:01 pm »
I tried using ./MinGW  but that didn't work.
Did you ever try to implement a methodology on Linux to get the full path of the application you are running currently? This isn't possible under certain circumstances - and I know no fail-safe way to do so. The usual way is to setup an env var pointing to the installation path. you cannot use argv[0] because this is mostly relative.

Thus how to obtain the full base path of C::B under such OS'es? If this would be possible a relative path to the compiler directory would be possible. But this isn't.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline joat

  • Single posting newcomer
  • *
  • Posts: 5
Re: Indefinite Paths in Compiler Installation Directory
« Reply #3 on: July 19, 2006, 09:27:27 pm »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Indefinite Paths in Compiler Installation Directory
« Reply #4 on: July 19, 2006, 10:04:19 pm »
Take a look at http://autopackage.org/docs/binreloc/
...that's a good one I didn't know to be honest. Anyway, for this minor purpose I read:
Code: [Select]
It's small, only about 20 KB of C source code (I suspect it's only about 10 KB if you remove all the inline documentation comments).
I wouldn't say for a self-allocation 10KB is small. Did you try the global variable hint? This works on all platforms and you have a minimalistic setup of 1 setting.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Indefinite Paths in Compiler Installation Directory
« Reply #5 on: July 19, 2006, 10:16:27 pm »
...do you know that you can also setup a path like "C:\$USERNAME" which is replaced with the environment variable %USERNAME% under Windows (and linux)?

Thus you can setup the path to the compiler like C:\Docume~1\$USERNAME\Desktop\CodeBlocks

???

Edit: BTW: You should avoid having spaces in the path to the compiler...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline BordRider

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Indefinite Paths in Compiler Installation Directory
« Reply #6 on: July 19, 2006, 11:06:13 pm »
Edit: BTW: You should avoid having spaces in the path to the compiler...

I learned THAT the hard way..I tried the same thing (putting the compiler in the codeblocks dir in "program files") and almost died...

We'll chock that one up to my ignorance though :P

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Indefinite Paths in Compiler Installation Directory
« Reply #7 on: July 20, 2006, 06:11:37 pm »
If you are using Boost.Filesystem this code will do it for you:
Code: [Select]
#include <iostream>
using namespace std;

#include <boost/filesystem/operations.hpp>
namespace bfs = boost::filesystem;

int main(int argc, char** argv)
{
    cout << "My full path: " << bfs::current_path().string() << endl;
}

Its tested and it works like a charm.  Gotta love boost.

Maybe we should check there implementation? Current_path uses getcwd on any Unix like platform.   On Windows it uses GetCurrentDirectory.  Or since we are using wxWidgets we can use wxGetCwd in wx/filefn.h.  Which I just tested and it works exactly the same.

Both give you the full path from root.

EDIT:   BinReloc listed above is cool because it will tell you where libraries and such are too.
« Last Edit: July 20, 2006, 06:36:36 pm by Game_Ender »