Are there any cross platform libraries that will help me place certain file in different directories. For example in windows a config file will probably go in app data, yet in Linux it will go in /etc/ or /use/etc/ depending on where it was installed. Is there any way to do this transparently?
boost::filesystem will should soon provide such functionalities (but not yet). I would be you, I'd use boost::filesystem and provide different addresses of user folders by platforms, then when boost::filesystem provide the feature, replace the implementations.
Did you try with Qt libraries?
Both QFileInfo( qApp->argv()[0] )::absFilePath ()
and QApplication::applicationDirPath() can work.
Related
I have a library that I distribute to my customers. I'm exploring the idea of leaving my 3rd party dependencies as dynamically linked dependencies. In this case, deployment for my customers becomes more complicated, as they must install my dependencies before they can use my library. I am a bit new to this, so I have a broad question:
Assuming that all of my customers are on linux, Is an RPM package that simply installs the dependency .so files into system library directories the best route? From what I'm reading about RPMs, this isn't really the way they are meant to be used. I suppose that what I'm looking for is a sort of 'installer' for linux, but maybe such a thing doesn't exist.
Is the best way to just build a package that includes all of the relevant binaries (and licenses, where applicable), and has instructions on how to install?
You have multiple options:
static linking (if the licenses in play allow it)
support a range of distros and provide packages for all of them (viability depends on who your customers are) . Easiest option for your customers, most complicated one for you.
provide an installer that installs your application in a Windows-style self-contained dir structure (eg /opt/myapp or /home/someuser/myapp). Put the shared libraries in there to and start via a script with LD_LIBRARY_PATH set accordingly. I've seen this option used by Loki games, Adobe Reader, Google Earth and others.
Do not:
provide a custom installer that will copy your binaries and libraries in the standard directory structure. This may overwrite specific library versions needed for other apps your customer has. It also leaves a terrible mess as the distro's package management won't know about these files.
provide an rpm for everyone. On non-rpm distros, this would require your customers to manually convert the package to fit their package management system.
I am not sure this strictly a programming question, so I apologize if it is not.
I developed a few libraries in C++ that I mean to use in several different projects.
Till now I kept copying the updated library in the folders of the various projects.
As you can imagine this is not ideal, so I would like to create a "3rd-parties" folder
where I save the libraries I write and other that I might download in the future.
How can I do this? And considering I'll want to share/release my code later on what is the best strategy to be sure that the used libraries are included in the code I deploy?
There are no hard and fast rules. But if these are 1) general-purpose, for 2) global sharing, then I'd suggest /usr/local/lib (for your .a and .so libraries) and /usr/local/include (for the corresponding headers).
Here's a good description of "standard file locations" for Linux:
http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/Linux-Filesystem-Hierarchy.html
If you want to share your modules with new project its better to organise them in a single folder and mark this folder as included library path in your new projects.
Is there a standard place to store configurations like database setting in c++? Just use xml file?
Need windows solution, but it is better to be platform independent.
Check out Boost Program Options. Apart from being one of the best command-line option processors in any language, it also supports reading configuration data from files with a syntax like INI, and using environment variables. It's suitable for exactly what it says: program options. If you have a huge variety or a hierarchy of configurations, however, you might better check out Boost Property Tree, which read INI files but also XML or JSON, and is probably better suited if you have a really large configuration.
No standard that I know of, but you have several libraries for program configuration, for example libconfig. Also, the Windows API has some utilities to parse INI files for programs, for example see this link.
Standard C++ is a language only, it don't know anything other than the language itself.
What you're asking totally depends on the libraries or framework you'll decide to use to connect to databases. There is no standard library that have this purpose. So first choose the database, then the library to connect to it, then you'll get the configuration infos in the library documentation.
There's nothing in the standard, but Boost.Program_options is a good library for retrieving/storing configuration.
Obviously the configuration file must be stored in the correct location: if it's a per-user configuration file, on Windows it will be stored in the %APPDATA%1 directory (usually in a subdirectory named after your application), on Linux in a dot file under the home directory. For non-user specific configuration files, they may be stored in the "All Users" Application Data folder on Windows1, and under /etc on Linux2.
Naturally, you won't hardcode these paths, but you'll use SHGetFolderPath with the appropriate CSIDL values (or SHGetKnownFolderPath if you don't care about pre-Vista compatibility), like CSIDL_APPDATA for per-user settings, CSIDL_COMMON_APPDATA for settings common to all users.
Notice that /etc on Linux is writeable only by the superuser; I don't remember if the "all users" profile is writable for normal users under Windows.
I come from a C# background and I am working on a C++ project. I need to open files in a directory, then process that data in the files. The problem is on my target environment (Greenhills Integrity), I cannot access a "directory". It seems C++ does not have a concept of a directory. Why not? This problem is simple in C#. I cannot link to any big library(BOOST or dirent) to get the files. I can open a file using fopen, but I won't always know the file names, so I have to "strcat" the directory to each filename in order to "fopen" the files.
I need a way to just get the file names in a directory without using an external API. Is that possible?
The major C++ APIs have directories. Start with readdir on POSIX or FindFirstFile() on Windows. Greenhills seems to support POSIX.
No, it's not possible. C++ has no "built-in" directory functionality - you need to use a library of some sort.
Check with your operating system. Directory handling is different for each. You will have to use the Windows 32 API if you want to list/query directories on Microsoft Windows, and the Linux API (e.g. opendir/stat) if you want to list/query directories on Linux.
I am running a Qt 4.5 commercial snapshot and want to use a plugin that I downloaded (it's a .so file) in my QWebView. Is there a specific location where I need to place this file? Can I grab it using the QWebPluginFactory?
I am assuming the plugin here is the NPAPI plugin (e.g. Flash). Under X11, QtWebKit search several common directories for the plugin. For the complete list, see the documentation on Netscape plugin support.
In addition to that, you must enable plugin support via QWebSettings::. See the documentation for WebAttribute::::PluginsEnabled, either globally or for your particular QWebView only.
If you're a commercial client you should be demanding your money earned support directly from the trolltech(nokia) guys.
Have you tried putting in the standard library directories? It should be picked up by the linker if it's in one of those directories.
For example:
/lib/
/usr/lib/
/usr/share/lib/
/usr/local/lib/
Have you tried looking around in /usr/lib/qt4/plugins/ or somewhere similar yet? I suppose that path will probably be where you have your 4.5 snapshot stuff compiled, but it should have options for putting in plugins for various things.