c++ boost library cannot open file - c++

I tried to work with the boost library to read/write configuration files but I just don't get it.
I even can't run the example code from boost.org (5 Minute Tutorial)
http://www.boost.org/doc/libs/1_49_0/libs/property_tree/examples/debug_settings.cpp
I've downloaded the boost_1_49_0.zip package and unzipped it to my c++ program folder. The code compiles (TheIDE - U++) but it always says "Error: debug_settings.xml: cannot open file" which basically means that the program works, but runs into the exception.
I didn't change the code, I just copy and pasted it to get a working example which I could try to understand then. But I don't even get this one to work. (Since it's exactly the same as in the link, I don't paste the code here... unless you think it's better.)
Please help me... or point to a different way to store variables in a file with some kind of structure (I wan't to learn a way that works for windows and linux, because some of my apps are cross-platform.)
Thanks.
EDIT: debug_settings.xml is in the same folder as the .cpp file
EDIT2: Working now, the debug_settings.xml is now in the folder where the executable is stored. (in my case, U++/TheIDE it's C:\upp\out\MyApps\MINGW.Debug.Debug_Full.Sse2 for debugging)

The configuration file would need to be in the working directory of the executable when it's running.

Related

Xcode writing to file issue

I'm trying to help my son with a Programming C++ for Engineers course. I got him set up with Xcode 13.1 on his iMac but I've never used it myself. That was working great until his first assignment that required writing output to a file. We created a new Command Line Tool project and then used the File->New->File... option to create an Empty file. After doing so, selecting that file and looking at the info on the right side of the window shows that the Full Path is pointing to the directory where his main.cpp file is. Yet, when running his code nothing was being written to the file. I had assumed that just referencing the file name in his code would cause it to use a local reference and look in the same directory as main.cpp. After much Googling I found a reference that said to go to Product->Scheme->Edit Scheme... then select the Options tab in the window that opens and change the Working Directory from "$(BUILT_PRODUCTS_DIR)" to the directory containing the main.cpp file. That got the programming working correctly. My questions are:
Is there a preference setting that would tell it to always use the current project directory so that we don't have to change this every time?
Where does "$(BUILT_PRODUCTS_DIR)" point to?
What should we be doing differently?

GraphicsMagick.NET missing CORE_RL_bzlib_.lib file, C++ linker error?

I'm a long time VB programmer, and pretty good with c#, but I'm dumb as a brick when it comes to c++. But nonetheless, I need to build the source code for GraphicsMagick.NET, specifically for .net 2.0 if I can, to try to see if I can convert it to a fully managed dll, so that I can import it into Unity3D (who cares why I need to build it?).
Anyway, without posting the entire project here, I realize it might be hard for anyone here to know exactly what is causing my error. But perhaps someone can give an educated guess? Edit: you can download a zip of the full source from https://graphicsmagick.codeplex.com/SourceControl/latest if you want to see all the code I'm working with that is giving me this error.
This project, I assume, is supposed to compile without errors right out of the box. But it doesn't. It has this line of code in the include.h file:
# if defined(HasBZLIB)
# pragma comment(lib, "CORE_RL_bzlib_.lib")
# endif
and as a result of this evil line, I'm getting this evil error:
LNK1104 cannot open file 'CORE_RL_coders_.lib'
GraphicsMagick.NET.net20
C:\Users\A\Downloads\graphicsmagick-d\GraphicsMagick.NET.net20\LINK 1
Being the good VB programmer, I searched my project folder extensively, and that _.lib file doesn't exist. But in the process of searching online, I learned that c++ sometimes generates .lib files when you build a project. So perhaps this file was supposed to be built first, before it was linked, but for whatever reason it didn't get built first? You can see how clueless I am with c++.
Of course I commented out the line. But then it simply generates an error on the next line, which is another .lib file missing. I assume it will generate an error on every _.lib file in the entire include.h file, and there are a fair number of them.
Why is this project, which is supposed to build, missing so many .lib files? Can anyone give an educated guess why? am I probably missing some dependency that the author of this project forgot to mention in the installation instructions? Or would it be more likely that these .lib files are supposed to be created by me somehow, and I'm just not building it right?
In the downloaded release under GraphicsMagick there are two script files called CopyLibsFromDropbox.cmd and CopyLibsToDropbox.cmd, the first of which contains
echo You can download the library files here: https://www.dropbox.com/sh/a8krszzmo76fqkt/AAAc9Jho29Jk3iLrKhsBmw-Ma?dl=0
goto done
In that dropbox, you will find all the lib files you need. Download the whole thing as a .zip and extract the thing inside the the \GraphicsMagick directory. Should look like that now:
Once the libs are inside that folder you can actually compile the code. The scripts are for copying them from your local dropbox directory to this directory, if you choose to "save this inside my dropbox" at the dropbox download page above. In the end, you should see something like
3> GraphicsMagick.NET.Web -> C:\Users\Maxi\Downloads\graphicsmagick-d1b5b1b28f26cdedf3ceeb555b94a87609286740\GraphicsMagick.NET.Web\bin\ReleaseQ16\x86\GraphicsMagick.NET.Web-x86.dll
3> Codeanalysis is beeing executed...
3> Codeanalysis finished -- 0 Errors, 0 Warning(s)
========== Build: 2 successfull, 0 failed, 0 recent, 1 skipped ==========
(who cares why I need to build it?)
I do. You can already include managed dlls to Unity, and GraphicsMagick.NET already gives you a .NET dll which you should be able to use within Unity, or did you have any particular problems with that? Need some image processing functionality from that library?

SDL IMG_loadTexture and other harddisks

I have recently started working on a small program with SDL2 and c++. In this program I used IMG_LoadTexture() to load a texture however it just would not want to work, the program could not find the image. So I chanced my program to use SDL_loadBMP(), did not work. After hours of endlessly looking for bugs I still could not find anything.
When I started my project I saved it to my D: disk and not on my C: disk. So when I was about to give up on the whole project I copied my exe, image and libraries to my C: disk and Boom it worked.
So I have no idea why this happens. I refer to my image with a relative path but it just doesn't want to work on my D: disk. Is this a bug? or might it have something to do with settings related to my disk? And how can I make it work on my D: disk?
P.S. I am using windows 7
P.S.S. My apologies in advance for any horrible grammar and spelling mistakes.
Is the working directory of you executable the same you assume it is? On windows happened more than one time that working directory was not the path I believed. With certain compiler configurations the working directory is not the same on wich the executable is, you have to change working directory looking at documentation of your IDE.
What frequently happened to me
CURRENT WORKING DIR
D:/projectdir/
EXPECTED WORKING DIR
D:/projectdir/bin/debug/
where files really are:
D:/projectdir/bin/debug/app.exe
D:/projectdir/bin/debug/texture.png
which files app is trying to loading when launched from IDE:
D:/projectdir/app.exe
D:/projectdir/texture.png
You can quickly test wich is current working directory by calling equivalent on windows of
getcwd (answer from here )
#include <WinBase.h>
int main() {
TCHAR pwd[MAX_PATH];
GetCurrentDirectory(MAX_PATH,pwd);
MessageBox(NULL,pwd,pwd,0);
}

Saving AVI files in C++ after creating

I'm using Wischik's example code for creating AVI files, however after I run the code and it exits successfully no AVI file is created. I looked through the code and cannot find where it writes/saves/creates an AVI file on your computer. Does anyone know where the code saves AVI file or if it doesn't, a way to make it save the AVI file created to your computer? Thanks
link to source code here
Wischik source code
You should find test.avi in the project directory. Since you know it's name, you could also use Windows explorer to search for it.
To examine further, (assuming you are using VC++), goto
Tools > Options > Projects and Solutions > VC++ Directories,
and Show Directories for Include files.
That will tell you where the headers are.
Alternatively, set a break point at the line where AVIFileOpen is called, and follow the execution path to see what it does.

WxWidgets - Unable to load images

I recently started working with WxWidgets (2.9.4) and was working through a tutorial I found, but it seems that I'm unable to load any images. I've already properly used the handler (for PNG) and the problem happens at run-time. Below is an image of the popup that is displayed when attempting to run the program.
Here is the code:
wxPNGHandler *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxBitmap exit;
exit.LoadFile(wxT("exit.png"), wxBITMAP_TYPE_PNG);
wxToolBar *toolbar = CreateToolBar();
toolbar->AddTool(wxID_EXIT, exit, wxT("Exit"));
toolbar->Realize();
Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(mainWindow::exitProg));
Any help is appreciated.
EDIT: I forgot to mention that when I click Cancel, this happens:
I placed the exit.png file in the build directory (/Debug or /Release) as well as the source code directory, but it still has yet to see it.
What is your working directory?
If you are using visual studio and running using the interface ( F5 or ctrl-F5 or the little run button in the toolbar ) then your working directory is the folder containing the project file. So try copying your image file there.
Or open a command window, cd to one of your build directories, and run your app from the command line.
In general, to avoid this sort of problem, I alter the project properties so that the executable is NOT stored in one of the build folders, but in a new folder ( which I usually call 'bin' - my unix roots are showing! ) and also alter the debugging properties so that the working directory is the bin folder.
There are a couple of advantages to this technique:
Both the release and trhe debug version use the same folder, so you only need one copy of any extra file, like your image file.
It is easy to see the executable and extra files in the working directory without being distracted by all the .obj files that end up in the build folders
IMHO this is well worth the little extra trouble in maintaining non default project properties.
First of all, to avoid problems deep inside wxToolBar, always check the return code of LoadFile() or, alternatively, use wxBitmap::IsOk() to check that the bitmap was successfully loaded.
Second, while adding the handler explicitly as you did is perfectly fine, I'd recommend to just call wxInitAllImageHandlers() as it's simpler and has no real drawbacks unless you are looking to create the smallest program possible.
Finally, to address your real problem, the file clearly doesn't exist at the path you're loading it from. You can, of course, solve this by being careful not to change your working directly (or restore it after changing it) in your program and by placing the file in the correct place. But this is, as you discovered, error-prone, so a better idea is to always use full paths to your resources. To construct them, you will find wxStandardPaths useful, in particular its GetResourcesDir() method.