SFML not loading image (Possibly due to placing in wrong place?) - c++

I'm not sure whether I'm doing something stupid or visual studio is doing something wrong.
I've never really used C++ with VS before, but I managed to get SFML working, and now I cannot load images.
This is how I put the image in the project:
However when I write:
if (!tileTexture.loadFromFile("ConceptTile.png"))
return EXIT_FAILURE;
It returns EXIT_FAILURE.
Can anyone give an answer to why this isn't working?
If it helps that png file isn't appearing anywhere in the debug directories, just dlls, exes, and pdbs.
I've looked online to try to find out where I am supposed to put images but I can't find any articles or help no matter what keywords I type.

Make sure you change the file properties within the project to copy it to the output directory. By default (and without further paths given in the string) SFML should look for the file in your working directory. You don't have to add image files to your project, if you ensure they're at the right place. Also make sure to not include them as resources (as SFML won't be able to load them without some additional code).

Open Windows Explorer and move to the folder that contains the C++ files and paste the image there and it shall work or make a folder and change the directory in code, for example, if you name the folder images :
(!tileTexture.loadFromFile("images/ConceptTile.png"))
return EXIT_FAILURE;
and it shall work.

Related

C++: Add resources to project template

Currently I have a C++ project template that contains some pre-installed images, defined as an array of bytes inside the code. I want to reorganize the project by moving images to resources, but the problem is that .rc script only accepts absolute paths to images, thus I don't quite understand how can I properly use them for project template. All I want is to place image files somewhere inside the project directory, and reference them in project .rc script using relative paths for portability. Is it even possible?
VS2019 Community 16.5.4 btw.
UPDATE1: I need to include my resources at compile time, thus dynamic file management is not an option. I have .rc file in a project and some PNG images inside it. They are defined using absolute paths like IDB_PNG1 PNG "D:\\absolute\\path\\to\\file.png". The problem is that I can't use paths relative to the project, like IDB_PNG1 PNG "\\path\\inside\\project\\file.png", getting zero portability of my resources in the template.
UPDATE2: One possible solution I've found is to use CustomParameter element and write paths in .rc file like IDB_PNG1 PNG "$projectpath$\\path\\inside\\project\\file.png", then set ReplaceParameters=True for .rc file in .vstemplate. But there is only $projectname$ default parameter and I'm not even sure I can do it for absolute path.
UPDATE3 (ANSWER): Thanks to this question I've found there is undocumented parameter $solutiondirectory$ (hopefully MS won't drop it from future releases). So I simply write my resources as IDB_PNG1 PNG "$solutiondirectory$\\$projectname$\\path\\inside\\project\\file.png" and then these paths are automatically updated by the Visual Studio when project is created. Problem solved!
Thanks to this question I've found there is undocumented parameter $solutiondirectory$ (hopefully MS won't drop it from future releases). So I simply write my resources as IDB_PNG1 PNG "$solutiondirectory$\\$projectname$\\path\\inside\\project\\file.png" and then these paths are automatically updated by the Visual Studio when project is created. Problem solved!
Assuming you are using a .rc file in the context of something like an icon image, it is possible. You can just use standard library to link to the image file and then read it byte for byte and load it into the arrays that you were using earlier.
If this is not the right context you could share some code for better understanding.

Why fatal error “LNK1104: cannot open file 'cryptlib.lib' occur when I compile a C++ project in Visual Studio?

I am getting the error mentioned above when compiling a project on Visual Studio. What is strange and different about my situation is that this works on my personal laptop, but not at work.
I have the entire project saved in Dropbox, because I sometimes work on my projects from work and I like this automatic sync that way I don't worry about loosing anything. Having said that, I use relative paths for my libraries, that way the folder is the same for both computers, i.e. "..\cryptopp\x64\Output\Debug\cryptlib.lib"
My question is, why does it work at home, but not at work? I made sure the property sheet has the correct path as well. The linker and VC++ directories are both relative paths.
This cryptlib.lib has some namespaces like CryptoPP and variable types such as byte, it won't give me an error on this. It knows it exists (I get the correct font color)
Is there something that I am missing?
P.S. Added screenshots per request. Can't add more than 2 links, so I merged 2 screenshots into 1. That ECE427Projects is where the solution file is located. I don't want to go any further back than that.
Screenshot 1
Screenshot 2
You've put the directory for the library in the wrong field.
There's two places you could use to specify the directory where your libraries are supposed to be. I prefer to use the Library Directories section in Configuration Properties→VC++ Directories, but the alternate is Additional Library Directories in Configuration Properties→Linker→General. There's no need to specify it in both locations, though I doubt anything bad will happen if you do. Bear in mind that this is supposed to be a directory, not a file, so delete the trailing cryptlib.lib file name from this directory string.
If you haven't, in Configuration Properties→Linker→Input, for Additional Dependencies, you should be putting the name of the library object (cryptlib.lib), in your case.
For all of these, make sure the default values inherited by the project property pages are still there, after the stuff you add.
Let me know if this doesn't resolve the issue.

Xcode C++ standalone files aren't compiled

Just started using c++ and I've built a little test program. All that happens is that a blue square follows your mouse around in a window. The problem is, that the image used doesn't seem to be IN the actual build file. If I delete the image from the images folder after the file is built, or send the build file to another person, the square doesn't show up.
I've searched around for answers but didn't find anything like this.
EDIT: I'm using SFML and just chose "SFML App" as a template.
EDIT AGAIN: Maybe it's because the image path is /Users/*/Desktop/ObjectiveCTests/Test/player.png. I'm not sure how to link it any other way. I've tried a lot of different paths.
Have you checked which build phase Xcode thinks your image file is part of?
You can find this out by clicking on your project, and then selecting the "Build Phases" tab, and then selecting your target. You should see a list of different build phases, each of which has several files in it. You want to make sure your image is part of the "Copy Bundle Resources" phase, not something else like "Compile Sources".
Take this with a grain of salt--I'm new to Xcode myself, but just had almost the exact same problem with my own project (except in my case it was a glsl fragment shader, not an image file, that wasn't getting bundled correctly.)

Q_IMPORT_PLUGIN compiling error with qgif and qjpeg plugin

I have some problem when a try to build my code upon the 4.7.4 dynamic version. I have linkage error because of the 2 following lines :
Q_IMPORT_PLUGIN(qgif)
Q_IMPORT_PLUGIN(qjpeg)
To resolve the problem i just commented the above lines. Now everything compile correctly, which is strange. Does that mean that the code is not using the plugin (look a stupid question, but the project has several hundred thousand lines, i don,t know every part of it)
Question : What is the purpose of qgif and qjped plugin. Should i expect code using explicitly functions form these plugins?
I just want to be sure that i will not broke something by committing these lines...
You'll only need those if you're linking the plugins statically. Since you're using the dynamic version, you don't need them, and can safely leave them out. You simply need to place the plugin DLL or SO files adjacent executable. If you open up the installation where you installed the Qt libraries to (in my case, G:\Libraries\Qt\4.7.1), you'll see a directory called 'plugins' which you can copy and paste into your project, adjacent to your executable.
As for the purpose of those plugins, they add support to QImage and the other Qt image related components for addition file formats so you can read and write, with varying levels of support. The level of support can be found here, under Reading and Writing Image Files.

Resource File VS2010: Images missing when copying product

I am creating a c++ dll which includes some images in the png format using VS2010. This works fine as long as I keep the dll on my developer machine. When I try to copy the dll to another machine the images are missing.
When I compile my project, a file called app.res is placed in the build directory. If I look into that file, it seems to contain some binary encoded pngs. The project settings contain a entry called "Resource File Name" in the "Resources" section. The value is "app.res". Therefor I assume that my resources are added to the dll. However, it apperently doesn't work that way.
Does anyone have any ideas what could be wrong here?
Does anyone know of any good instructions on how to deals with resource files in VS2010. The Microsoft documents just didn't help much..
The linker embeds the .res file in the DLL. Verify this with File + Open + File, select your DLL, you can browse the embedded resources. There is otherwise no mechanism to make embedded resources disappear when you copy the DLL, they are firmly embedded.