Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetDataDir always returning /usr/local

1 view
Skip to first unread message

Sebastien Senechal

unread,
Feb 23, 2008, 5:41:11 PM2/23/08
to
Using wxWidgets-svn with Linux kubuntu gutsy 2.6.22-14-generic

wxString currentDir = ::wxGetCwd();
wxStandardPathsBase& stdp = wxStandardPaths::Get();
wxLogMessage(stdp.GetDataDir());

The preceding call always return /usr/local/share/appname

I compile wxWidgets with --prefix=/usr
I configure my program with same option, install correctly in /usr, but data
is looked in /usr/local/ with the call above.

Does anyone has same issue ? Should return /usr...

thanks

sebastien

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
For additional commands, e-mail: wx-use...@lists.wxwidgets.org

Sebastien Senechal

unread,
Feb 23, 2008, 5:57:54 PM2/23/08
to
This is the result ouptut of the console sample application...
I believe this one is a bug. I presume wxWidgets 2.8.7 behaves also this way

*** Testing wxStandardPaths ***

Config dir (sys): /etc
Config dir (user): /home/seb
Data dir (sys): /usr/local/share/console
Data dir (sys local): /etc/console
Data dir (user): /home/seb/.console
Data dir (user local): /home/seb/.console
Documents dir: /home/seb
Executable
path: /data/opt/wx/wxWidgets-svn/GCCBuildReleaseConsole/samples/console/console
Plugins dir: /usr/local/lib/console
Resources dir: /usr/local/share/console
Localized res. dir: /usr/local/share/console/fr
Message catalogs dir: /usr/local/share/locale/fr/LC_MESSAGES


wxWidgets was configured (console version,, same result with GTK2):
../configure --prefix=/usr --disable-gui --disable-gtk --disable-gtk2 --without-opengl --without-odbc --disable-unicode --disable-debug --enable-exceptions

In the config.log:
prefix='/usr'

Vadim Zeitlin

unread,
Feb 23, 2008, 8:18:34 PM2/23/08
to
On Sat, 23 Feb 2008 17:41:11 -0500 Sebastien Senechal <sebastien...@videotron.ca> wrote:

SS> Using wxWidgets-svn with Linux kubuntu gutsy 2.6.22-14-generic
SS>
SS> wxString currentDir = ::wxGetCwd();
SS> wxStandardPathsBase& stdp = wxStandardPaths::Get();
SS> wxLogMessage(stdp.GetDataDir());
SS>
SS> The preceding call always return /usr/local/share/appname
SS>
SS> I compile wxWidgets with --prefix=/usr

Do you call wxStandardPaths::SetInstallPrefix() with this value? This
class can't magically know about configure arguments if you don't pass them
to it...

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Sebastien Senechal

unread,
Feb 23, 2008, 8:46:30 PM2/23/08
to
Hi vadim,

I cannot get a correct value from lib, so your advice is to set it before
getting it ?
I don't [assume to) know the prefix path, that's the whole point of calling
GetDataDir() !

the prefix path is passed to the configure script, default to /usr/local
my program "doesn't know" where the user install it when it specified
a --prefix. I use GetDataDir for that purpose...

I passed for the first time --prefix=/usr (debian package install there, not
local), and hence i cannot load any images or data since i cannot retrieve
the correct installation path ...

Even is wxWidgets is compiled using prefix /usr, calls to GetDataDir will
return /usr/local/share/appname, which is WRONG.

regards

seb

On February 23, 2008 20:18:34 Vadim Zeitlin wrote:
> GetDataDir

--

Sébastien Sénéchal
Cyberdine
4685 avenue de Lorimier
Montréal, H2H-2B4
(514) 998-8101

Vadim Zeitlin

unread,
Feb 23, 2008, 10:33:25 PM2/23/08
to
On Sat, 23 Feb 2008 20:46:30 -0500 Sebastien Senechal <s...@cyberdine.ca> wrote:

SS> I cannot get a correct value from lib, so your advice is to set it before
SS> getting it ?

Yes, you need to set the prefix.

SS> I don't [assume to) know the prefix path, that's the whole point of calling
SS> GetDataDir() !

But you do know the prefix path because your application presumably
defines PREFIX or something like this with the value passed to configure.

SS> the prefix path is passed to the configure script, default to /usr/local
SS> my program "doesn't know" where the user install it when it specified
SS> a --prefix.

It does, see above.

SS> I use GetDataDir for that purpose...

You're probably mistaken about the purpose of wxStandardPaths class then.
It doesn't attempt to discover where your executable is installed (although
we could do it for some systems, e.g. Linux, it would be unportable and
error-prone and, most importantly, completely unnecessary as you do,
indeed, already know where your program is installed in the usual case). It
just provides you with a convenient way to find the directories to use for
some standard purposes.

SS> I passed for the first time --prefix=/usr (debian package install there, not
SS> local), and hence i cannot load any images or data since i cannot retrieve
SS> the correct installation path ...
SS>
SS> Even is wxWidgets is compiled using prefix /usr,

Everything I wrote has nothing to do whatsoever with where wxWidgets was
installed. It's all about your program.

SS> calls to GetDataDir will return /usr/local/share/appname, which is
SS> WRONG.

No, it isn't. The behaviour is exactly as documented.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Sebastien Senechal

unread,
Feb 23, 2008, 11:49:20 PM2/23/08
to

On February 23, 2008 22:33:25 Vadim Zeitlin wrote:

> But you do know the prefix path because your application presumably
> defines PREFIX or something like this with the value passed to configure.

No i don't... it is an argument to configure, which is user dependent...
for portability reasons...

i.e. create a source archive, publish it on a website. A user download.
The user now decide to install this not in /usr/local, but for example
~/test/, hence it wil pass the "--prefix=~/test/app"

I use automake autoconf.... I don't have a setup.h....

> SS> my program "doesn't know" where the user install it when it specified
> SS> a --prefix.
> It does, see above.

it doesn't..... The configure script does, not my program (my code), which
needs to know where data files are stored (you know, the description of
GetDataDir in doc)

> SS> I use GetDataDir for that purpose...

> You're probably mistaken about the purpose of wxStandardPaths class then.
> It doesn't attempt to discover where your executable is installed

clearly one of us is mistaken. That's the reason of this thread.
I just expect functions to behave as to their descriptive

> (although we could do it for some systems, e.g. Linux, it would be
>unportable and
> error-prone

GetDataDir returns the correct path on all systems BUT linux (as per doc)...
For this function to work on linux, one has to set it, rendering this
function kinda useless

> and, most importantly, completely unnecessary as you do,
> indeed, already know where your program is installed in the usual case).

Since Obviously i don't ...
how do you do it ?

> Everything I wrote has nothing to do whatsoever with where wxWidgets was
> installed. It's all about your program.

I tried wxWidgets since GetDataDir was obviously ignoring i was in /usr/.
Was trying to find the source of problem, i dind't expect it to work

> SS> calls to GetDataDir will return /usr/local/share/appname, which is
> SS> WRONG.
>
> No, it isn't. The behaviour is exactly as documented.

After rereading the doc, I missed a function (avail just for linux)
GetInstallPrefix() which tries to retrieve /guess the prefix path....

haven't test it yet.... cause how do you call GetInstallPrefix or
SetInstallPrefix anyway ?

They are part of the class wxStandardPaths, but not wxStandardPathsBase... and
they are not static. I have no object to call them from. Anyone used these
functions ?

Also if GetInstallPrefix is actually able to retrieve correct path, why the
prefix value is stored in wxStandardPaths ... If it was in base, GetDataDir
would be able to produce correct output.

thanks

regards

Sebastien Senechal

unread,
Feb 24, 2008, 2:47:53 AM2/24/08
to
Hi

Realized this :

when i run the program in the output directory (meaning not in /usr/bin)
./projectsrc/src/optimized/program, GetDataDir returns /usr/local/share/app..

when i do a make install and run the program from /usr/bin
GetDataDir returns /usr/share/app...


It seems GetDataDir do some search. kinda make sense as per implementation

I bumped into this issue when i added a prefix comand in configure.in or
specifying at configure.
Executing a program outside /usr/bin produce issues finding the correct
path... hence since i use kdevelop, i can't execute from output build.

Does anyone has been through same problematic ?

quick workaround is to sym link ressources in /usr/local/share/
to /usr/share/dir for working / debugging

regards

seb

Vadim Zeitlin

unread,
Feb 24, 2008, 10:27:31 AM2/24/08
to
On Sat, 23 Feb 2008 23:49:20 -0500 Sebastien Senechal <s...@cyberdine.ca> wrote:

SS> On February 23, 2008 22:33:25 Vadim Zeitlin wrote:
SS>
SS> > But you do know the prefix path because your application presumably
SS> > defines PREFIX or something like this with the value passed to configure.
SS>
SS> No i don't...

Ok, look, I'm trying to help you. I'm sorry that I don't have enough time
to do this in perfect way and explain everything in all details. But even
this wouldn't help anyhow if you are not willing to think about what I'm
suggesting that you do and the phrase above suggests that you are not
because even if you don't do it currently it's not difficult to realize
that maybe I meant that you _should_ be doing it.


So let me just repeat once again how to use wxStandardPaths under Unix:

1. Define a makefile (AC_SUBST) or config.h (AC_DEFINE) variable containing
the value of prefix passed to configure. AFAIR configure already does
AC_SUBST(prefix) and while it may be more convenient to have it in
config.h, it's really up to you. In any case, even if you don't use
config.h, it's trivial to add "/DPREFIX=@prefix@" to your foo_CPPFLAGS
in your Makefile.am.

2. Call wxStandardPaths::SetInstallPrefix(PREFIX) in your code (inside
#ifdef PREFIX...) before using any accessors.

It's really not complicated, works 100% reliably and you shouldn't have any
trouble doing it if you choose to apply yourself to it.

If you don't, there is really nothing I can do to help you nor do I have
anything else to say on the subject, sorry.

VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Sebastien Senechal

unread,
Feb 24, 2008, 1:57:57 PM2/24/08
to

Hi Vadim

>1.

config.h seems the solution. would need to add a config.h.in

will check that approach

> In any case, even if you don't us  config.h, it's trivial to add "/DPREFIX=@prefix@" to your foo_CPPFLAGS  in your Makefile.am.

In the case i don't use config.h, maybe trivial, but I obviously don't know how, nor could I googled it. (accessing directly a PREFIX in my Makefile.am from my code without a config.h). that's why i am asking here :)

Not an expert in automake, autoconf. I will use a config.h.in but out of curiosity, please kindly show me how to do the magic if not using config.h.

> 2. Call wxStandardPaths::SetInstallPrefix(PREFIX) in your code

this will not compile.

Still morning, but same question as per last email, how do you call that function ?

SetInstallPrefix is not static so cannot call ::SetInstallPrefix

I don't have a object to call it from and if I use wxStandardPaths::Get(), i have a wxStandardPathsBase, which doesn't have S/GetInstallPrefix implemented...

this function is never used in wx/samples/

>0.

thanks for your time and reply.

Your initial advice to do a SetX() before GetX() doens't make sense to me for any topic and never will. As soon as i know what to give to SetX(), i don't need GetX() no more...

Let's just say I will call SetPrefixPath and move on.

I do take you advices into consideration, i also ave a right not to agree with you or take what you say at face value. That's why we exchange these mails to clarify questions.

have a good day

seb

Vadim Zeitlin

unread,
Feb 24, 2008, 5:18:47 PM2/24/08
to
On Sun, 24 Feb 2008 13:57:57 -0500 Sebastien Senechal <s...@cyberdine.ca> wrote:

SS> > In any case, even if you don't us  config.h, it's trivial to add
SS> > "/DPREFIX=@prefix@" to your foo_CPPFLAGS  in your Makefile.am.
SS>
SS> Not an expert in automake, autoconf. I will use a config.h.in but out
SS> of curiosity, please kindly show me how to do the magic if not using
SS> config.h.

By adding /DPREFIX as indicated above. If you have any problems with this,
I can't guess what they are if you don't say.

SS> > 2. Call wxStandardPaths::SetInstallPrefix(PREFIX) in your code
SS>
SS> this will not compile.

The code I post is meant to put you on the right track, not provide 100%
working, tested, debugged and documented solution. Sorry.

SS> Still morning, but same question as per last email, how do you call
SS> that function ? SetInstallPrefix is not static so cannot call
SS> ::SetInstallPrefix I don't have a object to call it from and if I use
SS> wxStandardPaths::Get(), i have a wxStandardPathsBase, which doesn't
SS> have S/GetInstallPrefix implemented...

It's true that Get() should return wxStandardPaths and not
wxStandardPathsBase probably, we've already discussed changing it in the
past. However you don't need to use it if you don't override
wxAppTraits::GetStandardPaths() anyhow, you can just create wxStandardPaths
object yourself and use it directly, Get() is meant to be used by wx own
code to allow its customization via wxAppTraits.

SS> Your initial advice to do a SetX() before GetX() doens't make sense to
SS> me for any topic and never will.

It's good to be so certain about something. Anyhow, I won't waste time
trying to explain it again then but just for the benefit of anyone else
reading this thread in the mailing list archives, let me repeat that
calling SetInstallPrefix() before calling other GetXXX() methods is exactly
the right thing to do.

SS> As soon as i know what to give to SetX(), i don't need GetX() no
SS> more...

This, of course, won't change your mind (as per above) but just as a
little thought experiment, try to think about how are you going to access
the data files of an application in a portable way.

And, FWIW, here is my version, which certainly doesn't make sense to you
(as per above) but nevertheless is the simplest way to do it I know of:

wxStandardPaths stdp;
#ifdef PREFIX
stdp.SetInstallPrefix(PREFIX);
#endif
wxString datadir = stdp.GetDataDir();

SS> I do take you advices into consideration, i also ave a right not to
SS> agree with you

Certainly. But if disagreeing becomes the main goal in itself, the
discussion is not very interesting (at least from my point of view) any
more.

Regards,

Fabian Cenedese

unread,
Feb 25, 2008, 7:28:15 AM2/25/08
to

>SS> I do take you advices into consideration, i also ave a right not to
>SS> agree with you
>
> Certainly. But if disagreeing becomes the main goal in itself, the
>discussion is not very interesting (at least from my point of view) any
>more.

Sometimes I admire your patience with this mailing list while still
doing some real development :)

bye Fabi

0 new messages