Undefined references with kos-ports

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
spencer723
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Jul 26, 2020 2:31 pm
Has thanked: 3 times
Been thanked: 8 times

Undefined references with kos-ports

Post by spencer723 »

Hi all, I'm trying to compile a test program with libGL/GLdc and everything seems to be compiling and installing just fine. The correct include files are in the kos-ports include directory and the libs are in there, too. Whenever I go to compile my program, I get a lot of these types of errors:

Code: Select all

/opt/toolchains/dc/sh-elf/bin/sh-elf-gcc -O2 -fomit-frame-pointer -ml -m4-single-only -ffunction-sections -fdata-sections  -I/opt/toolchains/dc/kos/include -I/opt/toolchains/dc/kos/kernel/arch/dreamcast/include -I/opt/toolchains/dc/kos/addons/include -I/opt/toolchains/dc/kos/../kos-ports/include -I/opt/toolchains/dc/kos/include -I/opt/toolchains/dc/kos/kernel/arch/dreamcast/include -I/opt/toolchains/dc/kos/addons/include -I/opt/toolchains/dc/kos/../kos-ports/include -D_arch_dreamcast -D_arch_sub_pristine -Wall -g -fno-builtin  -ml -m4-single-only -Wl,-Ttext=0x8c010000 -Wl,--gc-sections -T/opt/toolchains/dc/kos/utils/ldscripts/shlelf.xc -nodefaultlibs -L/opt/toolchains/dc/kos/lib/dreamcast -L/opt/toolchains/dc/kos/addons/lib/dreamcast -L/opt/toolchains/dc/kos/../kos-ports/lib -o Raycaster.elf  \
        raycast.o main.o romdisk.o  -lm -lkosutils -lGL -Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group
/opt/toolchains/dc/sh-elf/lib/gcc/sh-elf/9.3.0/../../../../sh-elf/bin/ld: /opt/toolchains/dc/kos/../kos-ports/lib/libGL.a(gl-api.o): in function `_glKosVertex3fpv':
/opt/toolchains/dc/kos-ports/libGL/build/libGL-2.0.0/gl-api.c:623: undefined reference to `__glKosVertexBufPointer'

...More errors similar to this...
Here is my main.c:

Code: Select all

#include <kos.h>

// kosext2fs
#include <ext2/fs_ext2.h>

// kosutils
#include <kos/bspline.h>
#include <kos/img.h>
#include <kos/md5.h>
#include <kos/netcfg.h>
#include <kos/pcx.h>
#include <kos/vector.h>

// libGL
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glu.h>
#include <GL/glut.h>

// math
#include <math.h>

// ppp
#include <ppp/ppp.h>

// raycasting methods
#include "raycast.h"

#ifdef DEBUG
#include <arch/gdb.h>
#endif

#define PACK_PIXEL(r, g, b) ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)

/* These macros tell KOS how to initialize itself. All of this initialization
   happens before main() gets called, and the shutdown happens afterwards. So
   you need to set any flags you want here. Here are some possibilities:

   INIT_NONE         -- don't do any auto init
   INIT_IRQ          -- Enable IRQs
   INIT_THD_PREEMPT  -- Enable pre-emptive threading
   INIT_NET          -- Enable networking (doesn't imply lwIP!)
   INIT_MALLOCSTATS  -- Enable a call to malloc_stats() right before shutdown

   You can OR any or all of those together. If you want to start out with
   the current KOS defaults, use INIT_DEFAULT (or leave it out entirely). */
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS);

/* Declaration of the romdisk
   You can access the files inside it by using the "/rd" mounting point. */
extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);

/* Your program's main entry point */
int main(int argc, char *argv[]) {
#ifdef DEBUG
	/* This is needed for the Debug target.
	   Please don't remove this part of code if you want to use the Code::Blocks debugger.
	   Also, you'll need to configure Dreamcast Tool (dc-tool) from the DreamSDK Manager. */
	gdb_init();
	printf("Connection established to %s!", PROJECT_NAME);
#endif

    /* Your program start here... */
    printf("\nHello world from %s!\n\n", PROJECT_NAME);

    glKosInit();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 100.0);   // setup a 10x10x2 viewing world

    glClearColor(0.29f, 0.46f, 0.84f, 1.0f);

    Floor_t floor = {
        .r = 1.0f,
        .g = 0.0f,
        .b = 0.0f
    };

    while(1) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        draw_floor(&floor);

        glutSwapBuffers();
    }

	/* Bye... */
    return 0;
}
Here is raycast.c:

Code: Select all

// libGL
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glu.h>

#include "raycast.h"


void draw_floor(Floor_t *floor) {
    glLoadIdentity();
    glOrtho(-5.0, 5.0, -5.0, 5.0, 0.0, 1.0);
    glColor3f(floor->r, floor->g, floor->b);
    glTranslatef(0.0f, 0.0f, 0.5f);

    glBegin(GL_QUADS);
        glVertex3f(-3.5f, 0.0f, 0.0f);
        glVertex3f(3.5f, 0.0f, 0.0f);
        glVertex3f(3.5f, -2.0f, 0.0f);
        glVertex3f(-3.5f, -2.0f, 0.0f);
    glEnd();
}
And this is my Makefile:

Code: Select all

#
# Basic KallistiOS skeleton / test program
# Copyright (C)2001-2004 Dan Potter
#   

# Put the filename of the output binary here
TARGET = Raycaster.elf

# List all of your C files here, but change the extension to ".o"
# Include "romdisk.o" if you want a rom disk.
OBJS = raycast.o main.o

# If you define this, the Makefile.rules will create a romdisk.o for you
# from the named dir.
KOS_ROMDISK_DIR = romdisk

# The rm-elf step is to remove the target before building, to force the
# re-creation of the rom disk.
all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean:
	-rm -f $(TARGET) $(OBJS) romdisk.*

rm-elf:
	-rm -f $(TARGET) romdisk.*

$(TARGET): $(OBJS) romdisk.o
	$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
		$(OBJS) romdisk.o $(OBJEXTRA) -lm -lkosutils -lGL $(KOS_LIBS)

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

dist:
	rm -f $(OBJS) romdisk.o romdisk.img
	$(KOS_STRIP) $(TARGET)
Any help would be greatly appreciated. I've tried reinstalling the ports. I feel like I'm missing something super simple :oops:
spencer723
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Sun Jul 26, 2020 2:31 pm
Has thanked: 3 times
Been thanked: 8 times

Re: Undefined references with kos-ports

Post by spencer723 »

Okay, so maybe the library isn't building correctly. When I install libGL, I get these errors when it's compiling:

Code: Select all

kos-cc  -c gl-light.c -o gl-light.o
In file included from gl-light.c:23:
gl-api.h:214:13: warning: inline function ‘_glKosPushMultiTexObject’ declared but never defined
  214 | inline void _glKosPushMultiTexObject(GL_TEXTURE_OBJECT *tex,
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
gl-api.h:89:18: warning: inline function ‘_glKosArrayBufPtr’ declared but never defined
   89 | inline glVertex *_glKosArrayBufPtr();
      |                  ^~~~~~~~~~~~~~~~~
gl-api.h:88:18: warning: inline function ‘_glKosArrayBufAddr’ declared but never defined
   88 | inline glVertex *_glKosArrayBufAddr();
      |                  ^~~~~~~~~~~~~~~~~~
gl-api.h:87:18: warning: inline function ‘_glKosArrayBufReset’ declared but never defined
   87 | inline void      _glKosArrayBufReset();
      |                  ^~~~~~~~~~~~~~~~~~~
gl-api.h:86:18: warning: inline function ‘_glKosArrayBufIncrement’ declared but never defined
   86 | inline void      _glKosArrayBufIncrement();
      |                  ^~~~~~~~~~~~~~~~~~~~~~~
      
      More...
spencer723
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Sun Jul 26, 2020 2:31 pm
Has thanked: 3 times
Been thanked: 8 times

Re: Undefined references with kos-ports

Post by spencer723 »

It seems as though my KOS toolchain install is okay. I was able to compile a simple PVR example that just clears the screen with red and it runs just fine.
User avatar
Ian Robinson
DC Developer
DC Developer
Posts: 116
Joined: Mon Mar 11, 2019 7:12 am
Has thanked: 212 times
Been thanked: 41 times

Re: Undefined references with kos-ports

Post by Ian Robinson »

Seems to me is this happening after your program builds if so it's the link line not working or you need to change the order.. -lGL should be -lgl Not caps _undefine is linking error should fix it change -lGl to -lgl let me know..

If it not built proper be a problem to
These users thanked the author Ian Robinson for the post:
spencer723
spencer723
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Sun Jul 26, 2020 2:31 pm
Has thanked: 3 times
Been thanked: 8 times

Re: Undefined references with kos-ports

Post by spencer723 »

Ian Robinson wrote: Mon Aug 03, 2020 8:59 am Seems to me is this happening after your program builds if so it's the link line not working or you need to change the order.. -lGL should be -lgl Not caps _undefine is linking error should fix it change -lGl to -lgl let me know..

If it not built proper be a problem to
Thanks for the suggestion! I actually ended up compiling GLdc myself in the kos-ports folder and using that instead of libGL. Once I compiled GLdc and changed my Makefile to use

Code: Select all

-lGLdc
instead of

Code: Select all

-lGL
, and changed the order so the GLdc was first in my declarations, I was able to compile my program.
These users thanked the author spencer723 for the post:
Ian Robinson
Post Reply