I cannot load a texture from a file (SFML c++) - c++

When I use the function .loadFromFile(), i get the following error:
undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string, std::allocator > const&, sf::Rect const&)'|
I have already tried different versions of SFML, and according to their website I'm using the correct one.
Here is my setup:
codeblocks-17.12mingw-setup.exe => download for codeblocks
SFML-2.4.2-windows-gcc-4.9.2-tdm-32-bit => SFML I am using
Here are my settings:
in the compiler tab
in the linker tab
The linking should be ok, as all the other SFML functions work. I have read that it could be because of SFML being compiled by a different compiler than mine? How can I check that? Is it something else that causes this problem?
here is the code :
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
using namespace sf;
int main () {
Texture texun;
texun.loadFromFile("C:\\Users\\j_hyl\\OneDrive\\Bureaublad\\Webdev\Apps\\Drive\\sprite.bmp");
return 0;
}

you have to link to sfml-graphics.lib or if your configuration is debug you have to link with sfml-graphics-d.lib and you have to copy the sfml-graphics-2.dll and sfml-graphics-d-2.dll(if debugging conf.) to the folder where your executable is

Related

Using SFML in Code::Blocks

I'm trying to make use of SFML in Code::Blocks. I've followed the guide at https://www.sfml-dev.org/tutorials/2.5/start-cb.php to the letter but it doesn't work. Please help!
In the project's build options I have specified everything:
Errors:
Here is simple code:
int main(){
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
sf::RenderWindow window(sf::VideoMode(800, 600), "Epic RPG");
return 0;
}
The errors seem to indicate that linking went wrong - I don't see how
I used CB's own SFML project type and it works now
I see that you are using static libs, if you want to use them you need to reference SFML source code as well. Instead, try to put the other same libraries but without the "-s" on them.

Cant use boost in xCode

When I am trying to use the boost library in xCode, i keep getting an error.
I have linked the header and link library like the tutorials say, but i am still getting an error
> #include <iostream>
> #include <string> // std::string
> #include <sstream> // std::stringstream
> #include <initializer_list>
> #include <vector>
> #include <boost/type_index.hpp>
> using std::cout;
> using std::endl;
at the boost index, my compiler says "'boost/type_index.hpp' file not found" when I try building..
How do i fix this?
In your Xcode project build settings, you must ensure you find/choose it in the the header search paths. (eg /usr/local/boost_1_60_0/include/)

How to include SDL2 and SDL_image on both Windows and Linux

I've been developing using C++ and SDL2 on Linux and have been using the following form to include SDL2 in my headers :
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
However, I now have need to develop on Windows too, which has a different include declaration. I've read up on it as best I can and have successfully included SDL using #include "SDL.h" and passing -I/usr/include/SDL2 into my makefile. This works fine for SDL, but seems to break SDL_image.
Using :
#include "SDL.h"
#include "SDL_image.h"
results in a long list of errors starting with
undefined reference to `IMG_Load'
Using
#include "SDL.h"
#include <SDL2/SDL_image.h>
with the -lSDL2_image flag results in
undefined reference to symbol 'SDL_FreeSurface'
Both of these errors I know are to do with SDL_image. The only thing that seems to work is
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
with the -lSDL2 -lSDL2_image when compiling, but I'd rather avoid that if possible so that I don't have to use #ifdef to compile on both Linux and Windows.
Can anyone point me in the right direction as to where I'm going wrong please?

OpenGL SOIL Undefined reference to glBindTexture, glTexImage2d, etc

I'm using C++ and Opengl, and I'm trying to use SOIL, but when I compile, I get undefined reference to glBindTexture, glTexImage2D, etc. However, this is only coming from SOIL.c, not my own source code. This is what the error produces:
http://pastebin.com/sKrQaBhz
My graphics card is NVIDIA GeForce GTX 680 and my drivers are fully updated. I have everything linked and I'm using premake to manage my project. I'm developing on a linux machine, however, I'm trying to cross compile it onto my windows machine, which gives this error. If I compile it on linux, it's completely fine. This is my premake4.lua file:
http://pastebin.com/T4hsbdz0
My include files is this:
#include "opengl/gl_core_3_3.hpp"
#include <GLFW/glfw3.h>
#include <SOIL/SOIL.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "loadshader.hpp"
I'm using mingw32 to compile my code. Before I was using SOIL, everything was fine. I downloaded SOIL from their webpage at lonesock.net, which I then copied over the libSOIL.a and their include files, but it just doesn't work.
Links order matters for g++.
Try this order:
links { "SOIL", "glfw3", "opengl32", "gdi32", "glu32" }
(edit: fixed the OP answer according to the duplicated question in Premake forum: http://industriousone.com/topic/how-use-premake-compile-static-library)
Looking at SOIL homepage, they said that it must be linked staticly. So, instead of using dynamic linking ('-l' in gcc compiler), try to specify the full path of the library.
This post illustrate what I want to say: https://stackoverflow.com/a/4156190/2293156
gcc -lsome_dynamic_lib some_static_lib.a code.c

Strange undefined reference !!! undefined reference to `std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'

When I am compiling my program
I am getting this error
undefined reference to `std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'
It feels that it is not albe to find reference in the standard libraries or something.
Is it some kind of lib conflict.
Basically I am trying to port piece of code which was on GCC 3.1.1 to 4.1.2
As there is compiler change I am facing this issue
Are you linking with other components still on 3.1.1 or even linking with the wrong GNU library?
Did you #include all the appropriate headers for the standard library components you're using?
For example,
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
Sound to me like you are using some c++ code.
'std' namespace and the 'template'.
Try using g++ to compile your code and if that doesn´t work try to put "using namespace std;" after your include lines.
Can you please provide atleast some few lines from where the error is from?
Btw found this link with the same question asked: Here
Where they suggest installing libstdc++.