Couldn't find sdl2.dll - c++

I'm trying to use sdl2, but when I try to run my program it gives me an error that says
code execution can't proceed because SDL2.dll couldn't be found. try reinstalling [...]
I'm compiling from the terminal, without any IDEs (I'm writing code in Sublime Text). My command looks like this
g++ src\main.cpp -o ..\..\test.exe -L lib\sdl32\lib -l SDL2 -I lib\sdl32\inc -m32
and my file system like this
I tried putting the .exe file in the same directory as the lib files, but it doesn't work.
I thought the problem might be that it's looking for SDL2.dll files and all of them are libSDL2.* and I tried changing the file names but it didn't work.
I also thought the problem was the extension, because they are all in *.dll.a, *.a or *.la, I tried changing that and it didn't work (I also tried a combination of the two).
This is my main.cpp
#define SDL_MAIN_HANDLED
#include <SDL.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 450, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(3000);
SDL_Quit();
return 0;
}
Am I missing a file or a compiler flag or something?

libSDL2.dll.a is an import library. You use it at compile-time to link the code to load the .dll into your binary. You will still need to have the SDL2.dll file at runtime which contains the actual implementation. On Windows, .dll files are searched in the PATH; the simplest way to use them is to put them in the directory that contains the executable.
The .dll file is available for download on the SDL website, you seem to only have the development files.

Related

"Undefined symbols for architecture x86_64" In SDL 2 (macOS)

Basically, I was trying to make my first SDL2 game in C but encountered the same error every time. Undefined symbols for architecture x86_64 Where i can't call simple functions like the SDL_CreateWindow from SDL. I thought something like this would happen because I have a very limited understanding of C and C++ as I only just learnt the language and concepts.
Originally, I downloaded the SDL 2 source code (SDL2.framework and put it into) the /Library/Frameworks file. Then I simply tried to include SDL2 by using the path #include </Library/Frameworks/SDL2.framework/Headers/SDL.h> to absolutely no avail.
I have tried looking up solutions but they all seem to be tutorials of EXACTLY what I have done or just answers for Windows users (I could rant about this).
I followed tutorials on the SDL website but I didn't understand them very well (I am new to shell and only 13) and most of the commands didn't work.
I tried troubleshooting the problem myself by looking inside of the SDL2 files and found these functions.
Please help, I have been searching for a while. Ideally I would just want a clear explanation (for newbies) on how to setup SDL2 so that I can compile my program with SDL2. This is what I tested:
#include <stdio.h>
#include "/Users/christianlincoln/Documents/programs/c/SDL2.framework/Versions/A/Headers/SDL.h"
int main(int argc, char * argv[]) {
SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
"Game", // window title
0, // initial x position
0, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
printf("Hello!\n");
return 0;
}
Sorry for wording my question wrong or being outright incompetent.
I think I figured it out, the problem was I also needed to compile the source libraries but I had no idea how to do this and how to ensure that gcc would link everything together.
All the other tutorials were just telling me to put the framework in /Library/Frameworks which was wrong.
Turns out I had to mess around with gcc for a while after compiling:
gcc game.c -I/usr/local/include/SDL2 -lSDL2
Although I am still unsure of how to do this with things like OpenGL.

How to Set Up SDL2 using Eclipse ubuntu

I've been trying to get SDL2 working with Eclipse on Ubuntu.
I have tried following this, this, and this but I just cannot get it working.
How can I get SDL2 working with Eclipse and have everything properly linked together?
EDIT:
When ever I compile the program it comes back saying that SDL.h is missing or there is no such directory, even though i can see SDL in the includes from the project list.
When compiling i have tried using:
gcc SDLTest.cpp
g++ SDLTest.cpp
gcc -o test SDLTest.cpp `sdl-config --cflags --libs`
I'm unsure of the difference between using GCC or G++, and i got the third compile from here.
I've added the SDL include folder to the project but still nothing
Image Project Explorer and Code
GCC C++ Linker Libraries
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
"an SDL2 Window",
20,
20,
640,
480,
SDL_WINDOW_OPENGL);
if (window == NULL)
{
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
`
This will install everything necessary to build programs that use SDL: sudo apt-get install libsdl2-dev
Create a new Eclipse project.
Go to properties of the project
C/C++ Build
Settings
GCC C++ Linker -> Libraries
Click on Add... and type SDL2
Apply and reindex the project
I used this documentation. Tested with SDL CreateWindow.

C++ SDL (Visual Studio 2015): cannot open file stddef.h

I'm relatively new to c++ and have been following the Lazy Foo' tutorial for installing SDL2 in visual studio 2010 (But I am using visual studio 2015).
I have followed the guide a couple of times now, so pretty certain I have incuded the right files etc. Here is a screen shot of my VC++ Directories settings:
#include <SDL.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window = 0;
window = SDL_CreateWindow("SDL window",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480,
SDL_WINDOW_SHOWN);
SDL_Delay(1000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
When compiled (32 bit) I receive this error:
......\documents\sdl\sdl2-2.0.4\include\sdl_stdinc.h(50): fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
I also have the error "cannot open source file stdio.h" when hovering over the include statement for stdio.h
I'm going to continue to look at it all, but if anyone has any suggestions that would be greatly appreciated. Failing that I'll probably just install on Linux :)
Cheers and thanks for your time.
Suggestions: Use the dropdown, (inherit from parent or project defaults) to repair the visual c++ directories which you shouldn't ever edit.
Don't add it to the c++ directories, That's a weird idea. Add it to Configuration Properties > c/c++ > additional include directories. If you had done that, then you couldn't have possibly messed up the compiler. It's a lot simpler too. Just paste the one directory in there. That's what it's meant for.
Also Lazy Foo seems to only to have a VS2010 guide. Maybe I just couldn't find the VS2015 guide...
The error message
fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
tends to happen when you're building your program with a version of MSVC different from the one used to build the library.
You should find out which version the SDL binaries were built with, and try using that. A newer MSVC might work, an older one might not.
You can always try building SDL yourself.

Undefined reference to 'glewExperimental', 'glewInit#0', '__glewGenBuffers'

I'm sorry if this is a duplicate question but I've looked through StackOverflow and Google and haven't come up with an answer yet.
I'm using Code::Blocks and SDL and trying to get GLEW working with openGL.
The program code is:
#include <Windows.h>
#include <SDL.h>
#define GLEW_STATIC
#include <glew.h>
int main(int argc, char *argv[])
{
//initialize SDL
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_Window* window = SDL_CreateWindow("OpenGL", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(window);
glewExperimental = GL_TRUE;
glewInit();
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
SDL_GL_DeleteContext(context);
SDL_Quit();
return 0;
}
When I build it, it returns:
undefined reference to 'glewExperimental'
undefined reference to 'glewInit#0'
undefined reference to '__glewGenBuffers'
It's not returning an error finding glew.h, so I assume it's a problem with the linker finding the .lib files.
I've added the folder where the .lib files are under Project > Build Options > Search Directories > Linker and added 'glew32s', 'glew32' (I've tried switching the precedence on glew32s and glew32), and 'opengl32' under Linker Settings > Link Libraries, and added '-lglew32s', '-lglew32' (again tried switching the precedence and removing one or the other), and '-lopengl32' under Linker Settings > Other linker options.
I even tried adding the .lib files, .h files, and .dll files to the project folder and adding search directories to the project folder. It still returns the same error.
I'm using the most recent version of glew (1.13.0) on a 64-bit OS. I've tried linking to the 64-bit and 32-bit versions (because I'd read most compilers compile in 32-bit by default for compatibility). Am I linking to the wrong files?
Thanks for reading.

C++ strange "undefined reference"

I'm relatively new to c++, so bear with a little.
I have a class with the constructor:
Window(int width, int height, const std::string& title);
As defined in the header file.
I then have the code:
#include "window.h"
int main(int argc, char** argv) {
new Window(800, 600, "Elysian Engine");
}
in Main.
When building, I am getting the error "undefined reference to 'Window(int, int, std::string const&)'" Which I do not understand, as I thought I am correctly importing it and everything. I understand this to be a linking error, but I'm not sure why.
Thanks!
--- EDIT ---
The code for window.cpp:
#include "window.h"
#include <SDL2/SDL.h>
#include <SDL/SDL.h>
#include <GL/glew.h>
Window::Window(int width, int height, const std::string& title) :
width(width),
height(height),
title(title),
isCloseRequested(false) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);
SDL_GL_SetSwapInterval(1);
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
}
}
Window::~Window() {
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
}
Because your code does not appear to be causing the issue, I will address the IDE.
When I first started using Code::Blocks, I ran into the "undefined reference" problem quite a bit. There are multiple ways that I solved this.
Exit Code::Blocks and re-open it. This solved my issues more times than I would care to count. It's similar to finally realizing that an executable is acting strangely because you needed to run make clean before compiling; sometimes, you are compiling an old version of code without realizing it.
Delete window.h and window.cpp from the project and re-add them. This is similar to the solution above. Although this has worked for me before, I couldn't figure out exactly why it worked.
Include the full path of window.h. Instead of #include "window.h", try #include "/path/goes/here/window.h". It is possible that your current location (as specified in your #include statement) is incorrect.
Check the compiler that is selected for the project. When I used Code::Blocks, I typically used gcc. However, there was a case where I was receiving all sorts of errors (upon attempting compilation) that I either did not understand or could not resolve, only to learn that I had accidentally selected some gcc variant from the compiler selection list that I did not even have installed.
Create a new project. Move your source files out of the project folder that is created by Code::Blocks, and then remove that project folder. Launch Code::Blocks, create a new project, and add your source files to the new project.
When all else fails and you absolutely must use Code::Blocks, reinstall the full package. I had to do this my first time using Code::Blocks (which was also my first time using an IDE). I realized that I had a bare-bones installation of the IDE, which was limiting what I could do (including compiling). Naturally, I cannot access the Code::Blocks website right now, otherwise I would offer a link here as well. In this case, I think it is safe to say that the full-featured stable version will be the largest (in MB) you can find on Code::Blocks' Downloads page. After you have reinstalled, create a new project and add your files back to it.
I eventually moved to using writing code in an IDE (for the linting!), and taking care of a makefile on my own. It has been awhile since I've used Code::Blocks, but each of the above bullets represents solutions/work-arounds that have helped me for your specific problem (or, in general) while I was using Code::Blocks.