undefined reference = pissing me off

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

undefined reference = pissing me off

Post by DrNicholas » Sat Oct 08, 2011 3:13 pm

I have set it up exactly to the hundreth percent how the tutorial says to. But I keep getting underfined reference.

Can I develop dc games in linux?
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Sat Oct 08, 2011 4:34 pm

supposedly its because my game is c++ and codeblocks is set for c. what do i do?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5387
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 1 time
Been liked: 12 times
Contact:

Re: undefined reference = pissing me off

Post by BlueCrab » Sat Oct 08, 2011 5:50 pm

You need to be a bit more specific than just "undefined reference". Copy/paste your entire compilation log, and provide us with the code in question, and maybe we'll be able to help.

Unfortunately, without that, we're more in the dark than you are.

From what I can gather from your post in the other topic, its because you're not linking in -lSDL. Adjust your Makefile so it links it in.
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Sat Oct 08, 2011 5:53 pm

I didn't see any tutorial for makefiles or any of that stuff. nor do i know anything about the -lDSL thing. It is just a tutorial I copied and pasted and added a couple dreamcast things towards:

Code: Select all

#include <kos.h>
#include <iostream>

using namespace std;

#include "SDL.h"

#define SCREEN_WIDTH  640
#define SCREEN_HEIGHT 480
#define SPRITE_SIZE     32

int gameover;

/* source and destination rectangles */
SDL_Rect rcSrc, rcSprite;

void HandleEvent(SDL_Event event)
{
	switch (event.type) {
		/* close button clicked */
		case SDL_QUIT:
			gameover = 1;
			break;

		/* handle the keyboard */
		case SDL_KEYDOWN:
			switch (event.key.keysym.sym) {
				case SDLK_ESCAPE:
				case SDLK_q:
					gameover = 1;
					break;
				case SDLK_LEFT:
					if ( rcSrc.x == 192 )
						rcSrc.x = 224;
					else
						rcSrc.x = 192;
					rcSprite.x -= 5;
					break;
				case SDLK_RIGHT:
					if ( rcSrc.x == 64 )
						rcSrc.x = 96;
					else
						rcSrc.x = 64;
					rcSprite.x += 5;
					break;
				case SDLK_UP:
					if ( rcSrc.x == 0 )
						rcSrc.x = 32;
					else
						rcSrc.x = 0;
					rcSprite.y -= 5;
					break;
				case SDLK_DOWN:
					if ( rcSrc.x == 128 )
						rcSrc.x = 160;
					else
						rcSrc.x = 128;
					rcSprite.y += 5;
					break;
			}
			break;
	}
}

int main(int argc, char* argv[])
{
	SDL_Surface *screen, *temp, *sprite, *grass;
	SDL_Rect rcGrass;
	int colorkey;

	/* initialize SDL */
	SDL_Init(SDL_INIT_VIDEO);

	/* set the title bar */
	SDL_WM_SetCaption("SDL Animation", "SDL Animation");

	/* create window */
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);

	/* set keyboard repeat */
	SDL_EnableKeyRepeat(70, 70);

	/* load sprite */
	temp   = SDL_LoadBMP("sprite.bmp");
	sprite = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);

	/* setup sprite colorkey and turn on RLE */
	colorkey = SDL_MapRGB(screen->format, 255, 0, 255);
	SDL_SetColorKey(sprite, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);

	/* load grass */
	temp  = SDL_LoadBMP("grass.bmp");
	grass = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);

	/* set sprite position */
	rcSprite.x = 150;
	rcSprite.y = 150;

	/* set animation frame */
	rcSrc.x = 128;
	rcSrc.y = 0;
	rcSrc.w = SPRITE_SIZE;
	rcSrc.h = SPRITE_SIZE;

	gameover = 0;

	/* message pump */
	while (!gameover)
	{
		SDL_Event event;

		/* look for an event */
		if (SDL_PollEvent(&event)) {
			HandleEvent(event);
		}

		/* collide with edges of screen */
		if (rcSprite.x <= 0)
			rcSprite.x = 0;
		if (rcSprite.x >= SCREEN_WIDTH - SPRITE_SIZE)
			rcSprite.x = SCREEN_WIDTH - SPRITE_SIZE;

		if (rcSprite.y <= 0)
			rcSprite.y = 0;
		if (rcSprite.y >= SCREEN_HEIGHT - SPRITE_SIZE)
			rcSprite.y = SCREEN_HEIGHT - SPRITE_SIZE;

		/* draw the grass */
		for (int x = 0; x < SCREEN_WIDTH / SPRITE_SIZE; x++) {
			for (int y = 0; y < SCREEN_HEIGHT / SPRITE_SIZE; y++) {
				rcGrass.x = x * SPRITE_SIZE;
				rcGrass.y = y * SPRITE_SIZE;
				SDL_BlitSurface(grass, NULL, screen, &rcGrass);
			}
		}

		/* draw the sprite */
		SDL_BlitSurface(sprite, &rcSrc, screen, &rcSprite);

		/* update the screen */
		SDL_UpdateRect(screen, 0, 0, 0, 0);
	}

	/* clean up */
	SDL_FreeSurface(sprite);
	SDL_FreeSurface(grass);
	SDL_Quit();

	return 0;
}
and the errors are
||=== AnnihilaPlatformEngine, default ===|
.objs\main.o||In function `main':|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_Init'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_RWFromFile'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_LoadBMP_RW'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_WM_SetCaption'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_DisplayFormat'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_SetVideoMode'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_EnableKeyRepeat'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_FreeSurface'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_MapRGB'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_SetColorKey'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_PollEvent'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_UpperBlit'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_UpdateRect'|
E:\Nick Lopez\Programming\NICK\AnnihilaPlatformEngine\main.cpp|152|undefined reference to `_SDL_Quit'|
||=== Build finished: 14 errors, 0 warnings ===|
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5387
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 1 time
Been liked: 12 times
Contact:

Re: undefined reference = pissing me off

Post by BlueCrab » Sat Oct 08, 2011 8:01 pm

You're using SDL, so you must link with it. Otherwise you will continue to get the linker errors. Edit your Makefile, and add -lSDL to the libraries you're linking with.

That's really the only advice I can give. Unfortunately, I don't use Code::Blocks, so I can't really tell you how one would do that with it.
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Sat Oct 08, 2011 9:49 pm

could you find me a template makefile and add it in there? my game is main.cpp and in the .obj filder its main.o or soemthing idk
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Sat Oct 08, 2011 9:52 pm

like this?
TARGET = main.elf
OBJS = main.o

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean:
-rm -f $(TARGET) $(OBJS)

rm-elf:
-rm -f $(TARGET)

$(TARGET): $(OBJS)
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
$(OBJS) $(OBJEXTRA) -lSDL -lparallax -lpng -lz -lm $(KOS_LIBS)

run: $(TARGET)
$(KOS_LOADER) $(TARGET)

dist:
rm -f $(OBJS)
$(KOS_STRIP) $(TARGET)
still get the error

What do you use? Are you able to test it on the PC?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5387
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 1 time
Been liked: 12 times
Contact:

Re: undefined reference = pissing me off

Post by BlueCrab » Sat Oct 08, 2011 11:36 pm

I'd imagine that somehow Code::Blocks is screwing things up. You need to find out what its doing that would cause it to not link properly. Just adding a Makefile to the project isn't going to do much good if Code::Blocks just ignores it.

That said, I don't use IDEs in general (at least not as IDEs) for Dreamcast stuff. I build all my stuff the old fashioned way, writing the Makefiles and running "make" in a terminal.
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Sat Oct 08, 2011 11:41 pm

well ill compile it in kos

so let me guess:
*you code in an IDE/notepad?
*you compile it in kos/cygwin?
*if so, what code do you use to compile in cygwin/kos?

I put my game in the cygwin folder, set cd to it and hit make.
error:
makefile:9: *** missing seperator
make file is exactly the same how it is up there. Could you edit the make file?
Ex-Cyber
DCEmu User with No Life
DCEmu User with No Life
Posts: 3641
Joined: Sat Feb 16, 2002 1:55 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by Ex-Cyber » Sun Oct 09, 2011 2:36 am

If it's exactly as you posted, it's definitely wrong. Indentation is syntactically significant in Makefiles, and must be done with actual tab characters. I don't think it's possible to post this on the forum, as the forum software will convert tabs to spaces even in a code block.
"You know, I have a great, wonderful, really original method of teaching antitrust law, and it kept 80 percent of the students awake. They learned things. It was fabulous." -- Justice Stephen Breyer
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 353
Joined: Wed Mar 30, 2011 12:13 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by RyoDC » Sun Oct 09, 2011 6:35 am

Yes, tabs are very important. Just pick one from the examples dir and this will work.
How do I try to build a Dreamcast toolchain:
Image
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Sun Oct 09, 2011 2:20 pm

I compiled something in dev-c++, and it worked!
How can I set up dev-c++ so it will compile for dreamcast?
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 353
Joined: Wed Mar 30, 2011 12:13 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by RyoDC » Mon Oct 10, 2011 8:20 am

Hmm, I recommend you to use original cygwin shell and compile in it. And you will get rid of the most of your problems. You can code and edit your files in graphical dev, but compile it in command mode. I think it's the best decision.
How do I try to build a Dreamcast toolchain:
Image
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Mon Oct 10, 2011 11:10 am

Am I still able to test compiled things on windows? Coders cables are extremely rare to come by now.
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 353
Joined: Wed Mar 30, 2011 12:13 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by RyoDC » Mon Oct 10, 2011 2:20 pm

Of course of course. And as for the encoder cable, especially since buying it, forget it. For such reasons: 1. its not that hard to solder and most 2. this thing is slow enough. You'll be tired up enough to throw through it the program, especially if it larger than 256 Kbytes. 3. a more rapid modification of the cable. For example usb-cable. Soldered by some unknown guy from England, who is personally familiar with Dan Potter (imagine!). Googling about him to the web, I'm pretty sure you'll find his page on the net, his site contains all the calculations and diagrams and etc. But it's certainly not bad if you understand about electronics and blowtorch you hold in the right organs of your body.
=)

P.S. By the way, as for your problem. I was to lame to answer but now I do. you simoply had the problems with linking headers (precede by directive '#include') files, IDE just was unable to find them. So, I've tested my environment, and it did all the job correctly! I've just done all that you've done (configuring using the manual in \Extras\Manuals\), and I'm using the same IDE.
Check, did you correctly filled that Window?
Image
Because I just successfully receive all the .ELF and needed bin files to work.
How do I try to build a Dreamcast toolchain:
Image
DrNicholas
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Sun Oct 02, 2011 5:33 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by DrNicholas » Mon Oct 10, 2011 2:52 pm

Id use nulldc, but for example, zelda roth is incredibly small in the emulator lol.
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 353
Joined: Wed Mar 30, 2011 12:13 pm
Has liked: 0
Been liked: 0

Re: undefined reference = pissing me off

Post by RyoDC » Mon Oct 10, 2011 2:58 pm

So did you read my post? :grin:
You're lucky. I can't even run modern releases of NullDC due to some glitch in my operation system (I use WinXP SP3 January 2011 with latest updates)
How do I try to build a Dreamcast toolchain:
Image
Post Reply