Jonathan.
Jonathan.

Reputation: 55604

Where to store resources for C++ program on linux

This question says the best place to store settings in linux is in ~/.config/appname

The program I'm writing needs to use a 99MB .dat file for recognizing facial landmarks, embedding it in the binary doesn't seem like a good idea.

Is there some default place to store resources on linux? currently it's just in the directory next to the executable, but this requires that the program is run with the current directory being the directory it's located in.

What's the best way to deal with resources like this on linux? (that could potentially be cross platform with at least OSX)

Upvotes: 7

Views: 1109

Answers (2)

Fabio Ceconello
Fabio Ceconello

Reputation: 16059

If the file is specific to the user running the app, it should be in a subdir of ~/ but AFAIK there's no standard, and the best choice depends much on the file type/usage. If it should be visible to the user via GUI, you could use ~/Desktop or ~/Downloads. If it's temporary, you can use ~/tmp or ~/var/tmp.

If it's not specific, you should place it in a subdir of /var. Again, the exact subdir may depend on its kind and other factors.

Upvotes: 0

Schiem
Schiem

Reputation: 589

You should take a look at the Filesystem Hierarchy Standards. Depending on the data (will it change, is it constant across all installations, etc) the path where it gets placed will change based on the standards.

In general:

  • /usr/lib/program: includes object files, libraries, and internal binaries for an application
  • /usr/share/program: for all read-only architecture independent data files
  • /var/lib/program: holds state information pertaining to an application or the system

Those seem like pretty good places to start, and you can check the documentation to see if your app falls into one of those categories.

Upvotes: 4

Related Questions