Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Ive been trying to make a game using SDL2

C++
if(!(IMG_Init(IMG_INIT_PNG)))
{
       std::cout << "ERROR: IMG_INIT HAS FAILED: "<< IMG_GetError() << std::endl;
}

When i try to run the code the following error message pops up:

"Undefined symbols for architecture x86_64:"

This also happens when i try using the "LoadTexture" function

C++
SDL_Texture* texture = NULL;
   texture = IMG_LoadTexture(renderer, p_filePath);


Trying to run/build throws a similar error:


Undefined symbols for architecture x86_64:
"_IMG_LoadTexture", referenced from:
RenderWindow::loadTexture(char const*) in renderwindow-a17af6.o


I would appreciate any help as im new to using the SDL2 library

What I have tried:

Ive tried downloading the newest version of SDL2, but that didn't work
Posted
Updated 13-Jul-22 3:08am
Comments
Rick York 5-Jul-22 16:36pm    
I think that message means there is problem linking. This is often caused by not correctly telling the linker where the library file is.
HardCoreHam 7-Jul-22 17:52pm    
#include <iostream>
#include <sdl2 sdl.h>
#include <sdl2 sdl_image.h>
#include "RenderWindow.hpp"

is what i have on my main.cpp file, would this be correct?
Rick York 7-Jul-22 19:49pm    
As as I know it would be but I don't use OS-X or SDL. Usually header files do not affect linking unless they have pragmas that define the libraries to link with. This problem is usually caused by not specifying the correct path to the library files.

Hit the same error with SDL after unpacking zlib1.dll (version 1.2.8) from SDL2_ttf-devel-2.0.14 to my compiler's bin folder, much like unpacking to your MySysWow64 folder which I'd be much less inclined to do. Searching the error "The procedure entry point inflateValidate" will pull up lots of zlib1.dll conflict results. The zlib1.dll (1.2.11) from SDL2_image-devel-2.0.4 worked where the 1.2.8 version generated the error you report. Delete zlib1.dll and find a newer version, also consider that there may be another conflicting zlib1.dll already in your PATH somewhere else which is causing the error, check your PATH for other copies of the DLL.
 
Share this answer
 
I think that's the same error when you missed "
-lSDL2_image
"

-lSDL2_image<pre>.
is a linker to a library for SDL. When you forgot to add the linker that same error occurs i think
 
Share this answer
 
v2
Comments
Dave Kreskowiak 13-Jul-22 9:43am    
If you want this to be an acceptable answer, you're going to have to explain what you mean by "missed -lSDL2_image".

Missed where? What does this do?
bonezegei 13-Jul-22 9:53am    
-lSDL2_image is a linker to a library for SDL. When you forgot to add the linker that same error occurs i think.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900