Sign in to follow this  
Noegddgeon

XCode Can't Find SDL_image

Recommended Posts

Noegddgeon    134
Hello, everybody. I'm going through this tutorial here: http://lazyfoo.net/SDL_tutorials/lesson04/index.php In the tutorial previous to this one, it explained how to download an extension library for SDL called "SDL_image", which enables me to load other image formats into a program aside from simply ".bmp" files. I downloaded "SDL_image", placed the Framework into my Frameworks folder, and that was that. (Btw, I'm using a Mac with Mac OS 10.5.7 and XCode Version 3.1.4) I then made an XCode project with the following source code:
#include "SDL.h"
#include "SDL_image/SDL_image.h"
#include <string>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

SDL_Surface *image = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;

SDL_Surface *load_image(std::string filename)
{
	SDL_Surface* loadedImage = NULL;
	SDL_Surface* optimizedImage = NULL;
	loadedImage = IMG_Load(filename.c_str());
	
	if (loadedImage != NULL)
	{
		optimizedImage = SDL_DisplayFormat(loadedImage);
		SDL_FreeSurface(loadedImage);
	}
	
	return optimizedImage;
}

void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
	SDL_Rect offset;
	
	offset.x = x;
	offset.y = y;
	
	SDL_BlitSurface(source, NULL, destination, &offset);
}

bool init()
{
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
	{
		return false;
	}
	
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
	
	if (screen == NULL)
	{
		return false;
	}
	
	SDL_WM_SetCaption("Event test", NULL);
	
	return true;
}

bool load_files()
{
	image = load_image("x.png");
	
	if (image == NULL)
	{
		return false;
	}
	
	return true;
}

void clean_up()
{
	SDL_FreeSurface(image);
	
	SDL_Quit();
}

int main(int argc, char* args[])
{
	bool quit = false;
	
	if (init() == false)
	{
		return 1;
	}
	
	if (load_files() == false)
	{
		return 1;
	}
	
	apply_surface(0, 0, image, screen);
	
	if (SDL_Flip(screen) == -1)
	{
		return 1;
	}
	
	while (quit == false)
	{
		while (SDL_PollEvent(&event))
		{
			if (event.type == SDL_QUIT)
			{
				quit = true;
			}
		}
	}
	
	clean_up();
	
	return 0;
}
I linked the project to the Framework of SDL_image and then ran the source code. Originally, it was fine, but there was an error upon running the program that told me "Jam" was deprecated and that I should "Upgrade all Targets in the Project to Native". I did this, and following this, it's not finding "SDL_image" any longer, even though the Framework is visibly linked to the project. I am wondering if anyone here may know how to solve this problem, and I would be very appreciate if so. Thank you very much for your time. Colton

Share this post


Link to post
Share on other sites
szymczyk    182
Some things to consider.

First, you said you made an Xcode project, but you didn't say what type of Xcode project you created. You should be using one of the SDL Xcode project templates as a starting point and add the SDL_image framework to the project.

Second, my Mac code that uses SDL_image has the following include for the SDL_image header:

#include "SDL_image.h"

Third, you may need to add search paths for the SDL_image framework and headers so Xcode can find them. In Xcode choose Project > Edit Project Settings and click the Build tab in the project inspector. The build settings Framework Search Paths and Header Search Paths are part of the Search Paths build settings collection.

Share this post


Link to post
Share on other sites
Noegddgeon    134
szymczyk,

Thank you for your reply. I looked in my Search Paths section and there are no Header Search Paths or Framework Search Paths in either field. Do you think that this could be the problem? The program seems to be aware that SDL exists, though, which is linked to the project, as well.... so I don't understand how it could detect the SDL framework and not the SDL_image Framework. Thank you for your time.

Colton

Share this post


Link to post
Share on other sites
szymczyk    182
If you're getting linker errors about missing symbols for SDL_image calls or getting error messages saying SDL_image.h can't be found, the missing search paths are the most likely cause of the error. Add the search paths and see if doing so fixes the problem.

Share this post


Link to post
Share on other sites
szymczyk    182
Double-click the Header Search Paths build setting in the project inspector. Refer to my first post for instructions on opening the project inspector. When you double-click the build setting, a sheet will open. Click the + button to add a search path. Double-click the path in the sheet to enter the path. Adding a framework search path is similar.

Share this post


Link to post
Share on other sites
Noegddgeon    134
szymczyk,

I entered the search paths for both SDL_image.h and SDL_image.framework, but to no avail.

If it helps, I was previously able to compile and run the program before I clicked on the "Upgrade all Targets in Project to Native" command in the "Project" menu. Upon doing that is when it could no longer find SDL_image.h. However, back when I was running it with "Jam", it would open and then close within the blink of an eye. At the time, I couldn't figure out what was wrong with the program.

I hope this helps in any way in finding a solution to this problem.... I would love to make some use out of SDL, but that's assuming I can even get the library to work. :p Thank you very much for your time and patience.

Colton

Share this post


Link to post
Share on other sites
szymczyk    182
Go to my website and send me an email.

http://www.meandmark.com

I can email you a simple Xcode project that uses SDL_image to load an OpenGL texture. You can examine the project and see what's different in your setup.

Share this post


Link to post
Share on other sites
Noegddgeon    134
My problem was that I had SDL_image.framework in Users/coltonogden/Library/ instead of just /Library/. Upon placing the framework into the correct library, I got the program to run. Then, once I was running the program successfully, I fixed the error of the screen appearing quickly and disappearing by putting the image file into the /Debug folder in the /build directory.

Thanks to szymczyk for all your help!

Colton

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this