Code::Blocks Forums

User forums => Help => Topic started by: joat on July 19, 2006, 07:59:20 pm

Title: Indefinite Paths in Compiler Installation Directory
Post by: joat 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.
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: MortenMacFly 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?
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: MortenMacFly 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.
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: joat on July 19, 2006, 09:27:27 pm
Take a look at http://autopackage.org/docs/binreloc/ (http://autopackage.org/docs/binreloc/)
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: MortenMacFly on July 19, 2006, 10:04:19 pm
Take a look at http://autopackage.org/docs/binreloc/ (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
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.
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: MortenMacFly 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...
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: BordRider 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
Title: Re: Indefinite Paths in Compiler Installation Directory
Post by: Game_Ender on July 20, 2006, 06:11:37 pm
If you are using Boost.Filesystem this code will do it for you:
Code
#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 (http://www.gnu.org/software/libc/manual/html_node/Working-Directory.html#index-getcwd-1382) on any Unix like platform.   On Windows it uses GetCurrentDirectory (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getcurrentdirectory.asp).  Or since we are using wxWidgets we can use wxGetCwd (http://www.wxwindows.org/manuals/2.6.3/wx_filefunctions.html#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.