#Include datafile "undefined reference" error

SGDK only sub forum

Moderator: Stef

Post Reply
MrTamk1s
Very interested
Posts: 75
Joined: Sun Jan 04, 2015 10:27 pm
Location: Pennsylvania
Contact:

#Include datafile "undefined reference" error

Post by MrTamk1s »

Long time lurker, new poster!

Just to give a very quick introduction about myself, I'm a Software Engineering student who is looking to get into video game development post-graduation. I am big into the Sega Genesis and its add-ons, have some basic experience with M68k and C, and have some prior minor experience with Sega development with "hom racking" and BEX development. Wanting to have some more power over homebrew development and to gain more C experience, I have recently moved from BEX dev to SGDK dev.
---------------------------------

Enough about me, currently, I am working on moving a recently cancelled air hockey BEX project to a more solid foundation with SGDK (BEX was too buggy and limited and was breaking with the dev of the game), starting with moving over the Echo sound driver I used. I followed this guide on implementing Echo with SGDK, and even made a correction about the guide (see my post at Thu Jan 15, 2015 4:01 am). However, despite following the original guide and my fix for it, and despite using rescomp to compile my Echo eif, ewf, and esf asset files into a .h header file and .s object file, I am receiving the following errors on compilation with Code::Blocks when defining the Echo instruments pointer array in main.h

Code: Select all

out/src/echo.o:(.rodata+0x4): undefined reference to `PCM_01'
out/src/echo.o:(.rodata+0x8): undefined reference to `PCM_02'
out/src/echo.o:(.rodata+0xc): undefined reference to `PCM_03'
out/src/echo.o:(.rodata+0x10): undefined reference to `PCM_04'
out/src/echo.o:(.rodata+0x14): undefined reference to `PCM_05'
out/src/echo.o:(.rodata+0x18): undefined reference to `PCM_06'
out/src/echo.o:(.rodata+0x1c): undefined reference to `PCM_07'
(etc, for all echo instruments)
Process terminated with status 2 (0 minute(s), 3 second(s))
50 error(s), 0 warning(s) (0 minute(s), 3 second(s))
Oddly enough, despite explicitly defining the array names for each file Echo file using rescomp, the compiler still can't find the pointers to the files! What am I doing wrong? Am I supposed to put the rescomp generated .s file somewhere particular?

Code for relevant files:

Code: Select all

main.c:

#include <genesis.h>
#include "main.h"

int main ( void )
{
        //Init variables here

        // Initialize Echo
        echo_init(*Instruments);        // Load Instruments
        echo_set_pcm_rate(4);        // Default PCM Rate
        echo_play_bgm(BGM_01);    // Play your Song

        JOY_init();
        VDP_drawText("Hello Universe!",1,1);

        // Mainloop
        while(1)
        {
                // Wait for screen refresh
                VDP_waitVSync();
        }

        // This will never be reached :( Oh noes!
        return(0);
}

Code: Select all

Main.h:

//Boolean constants/Debug stuff
#include "echo.h"
#include "../res/Echo/data/Musres.h"

static const void* const Instruments[] =
{
    PCM_01,PCM_02,PCM_03,PCM_04,PCM_05,PCM_06,PCM_07,PCM_08,PCM_09,PCM_10,
    PCM_11,PCM_12,PCM_13,PCM_14,PCM_15,PCM_16,PCM_17,PCM_18,PCM_19,PCM_20,
    PCM_21,PCM_22,PCM_23,PCM_24,PCM_25,PCM_26,PCM_27,PCM_28,PCM_29,PCM_30,
    PCM_31,

    FM_1_01,FM_1_02,FM_1_03,DAC_1_01,FM_1_04,DAC_1_02,DAC_1_03,DAC_1_04,DAC_1_05,DAC_1_06,
    DAC_1_07,DAC_1_08,DAC_1_09,FM_1_05,FM_1_06,DAC_1_10,DAC_1_11,

    FM_3_01,FM_3_02,FM_3_03,FM_3_04,

    DAC_4_01,DAC_4_02,DAC_4_03,FM_4_01,FM_4_02,FM_4_03,FM_4_04,FM_4_05,FM_4_06,FM_4_07,

    FM_5_01,FM_5_02,FM_5_03,DAC_5_01,FM_5_04,DAC_5_02,DAC_5_03,FM_5_05,FM_5_06,DAC_5_04,
    DAC_5_05,FM_5_07,FM_5_08,DAC_5_06,FM_5_09,FM_5_10,

    DAC_6_01,DAC_6_02,FM_6_01,FM_6_02,FM_6_03,FM_6_04,FM_6_05,FM_6_06,FM_6_07,FM_6_08,
    FM_6_09,FM_6_10,

    DAC_7_01,DAC_7_02,DAC_7_03,FM_7_01,FM_7_02,FM_7_03,

    DAC_8_01,DAC_8_02,DAC_8_03,DAC_8_04,FM_8_01,FM_8_02,FM_8_03,FM_8_04,

    FM_9_01,FM_9_02,FM_9_03,FM_9_04,FM_9_05,FM_9_06,FM_9_07,

    FM_10_01,FM_10_02,FM_10_03,

    DAC_11_01,DAC_11_02,FM_11_01,DAC_11_03,DAC_11_04,DAC_11_05,FM_11_02,FM_11_03,FM_11_04,FM_11_05,

    DAC_12_01,FM_12_01,FM_12_02,FM_12_03,FM_12_04,

    DAC_13_01,DAC_13_02,DAC_13_03,FM_13_01,FM_13_02,FM_13_03,

    DAC_14_01,DAC_14_02,DAC_14_03,FM_14_01,FM_14_02,FM_14_03,

    PCM_31,PCM_32
};

Code: Select all

echo.h:

#ifndef ECHO_H
#define ECHO_H

#include <types.h>
#inlcude "echo_blob.h"

//Echo commands
enum {
   ECHO_CMD_NONE,          //0x00 - No command
   ECHO_CMD_LOADLIST,      // 0x01 - Load instrument list
   ECHO_CMD_PLAYSFX,       // 0x02 - Play a SFX
   ECHO_CMD_STOPSFX,       // 0x03 - Stop SFX playback
   ECHO_CMD_PLAYBGM,       // 0x04 - Play a BGM
   ECHO_CMD_STOPBGM,       // 0x05 - Stop BGM playback
   ECHO_CMD_RESUMEBGM,     // 0x06 - Resume BGM playback
   ECHO_CMD_SETPCMRATE,    // 0x07 - Set PCM rate
};

//Echo status flags
#define ECHO_STAT_BGM      0x0002   //Background music is playing
#define ECHO_STAT_SFX      0x0001   //Sound effect is playing
#define ECHO_STAT_BUSY     0x8000   //Echo still didn't parse command

//Function prototypes
void echo_init(const void **);
void echo_play_bgm(const void *);
void echo_stop_bgm(void);
void echo_resume_bgm(void);
void echo_play_sfx(const void *);
void echo_stop_sfx(void);
void echo_set_pcm_rate(uint8_t);
uint16_t echo_get_status(void);
void echo_send_command(uint8_t);
void echo_send_command_addr(uint8_t, const void *);
void echo_send_command_byte(uint8_t, uint8_t);

//Deprecated functions
static void (* const echo_send_command_ex)(uint8_t, const void *) =
   echo_send_command_addr;

#endif

Code: Select all

musres.h
#ifndef _MUSRES_H_
#define _MUSRES_H_

extern const u8 SFX_01[772];
extern const u8 SFX_02[772];
extern const u8 SFX_03[772];
extern const u8 SFX_04[772];
extern const u8 SFX_05[772];
extern const u8 SFX_06[772];
extern const u8 SFX_07[772];
extern const u8 SFX_08[772];
extern const u8 SFX_09[772];
extern const u8 SFX_10[772];
extern const u8 SFX_11[772];
extern const u8 SFX_12[772];
extern const u8 SFX_13[772];
extern const u8 SFX_14[772];
extern const u8 SFX_15[772];
extern const u8 SFX_16[772];
extern const u8 SFX_17[772];
extern const u8 SFX_18[772];
extern const u8 SFX_19[772];
extern const u8 SFX_20[772];
extern const u8 SFX_21[772];
extern const u8 SFX_22[772];
extern const u8 SFX_23[772];
extern const u8 SFX_24[772];
extern const u8 SFX_25[772];
extern const u8 SFX_26[772];
extern const u8 SFX_27[772];
extern const u8 SFX_28[772];
extern const u8 SFX_29[772];
extern const u8 SFX_30[772];
extern const u8 SFX_31[772];
extern const u8 SFX_32[900];
extern const u8 SFX_33[900];
extern const u8 BGM_01[5386];
extern const u8 BGM_02[18326];
extern const u8 BGM_03[11292];
extern const u8 BGM_04[32388];
extern const u8 BGM_05[51402];
extern const u8 BGM_06[23410];
extern const u8 BGM_07[16410];
extern const u8 BGM_08[12110];
extern const u8 BGM_09[24826];
extern const u8 BGM_10[12344];
extern const u8 BGM_11[14848];
extern const u8 BGM_12[5260];
extern const u8 BGM_13[9236];
extern const u8 BGM_14[15216];
extern const u8 PCM_01[3452];
extern const u8 PCM_02[5126];
extern const u8 PCM_03[5126];
extern const u8 PCM_04[1578];
extern const u8 PCM_05[3738];
extern const u8 PCM_06[10250];
extern const u8 PCM_07[3844];
extern const u8 PCM_08[64792];
extern const u8 PCM_09[12814];
extern const u8 PCM_10[21832];
extern const u8 PCM_11[10252];
extern const u8 PCM_12[10250];
extern const u8 PCM_13[27728];
extern const u8 PCM_14[4144];
extern const u8 PCM_15[7688];
extern const u8 PCM_16[5198];
extern const u8 PCM_17[7688];
extern const u8 PCM_18[10250];
extern const u8 PCM_19[5150];
extern const u8 PCM_20[4136];
extern const u8 PCM_21[4100];
extern const u8 PCM_22[5126];
extern const u8 PCM_23[3868];
extern const u8 PCM_24[2890];
extern const u8 PCM_25[7688];
extern const u8 PCM_26[5126];
extern const u8 PCM_27[15376];
extern const u8 PCM_28[6220];
extern const u8 PCM_29[10250];
extern const u8 PCM_30[6312];
extern const u8 PCM_31[17124];
extern const u8 PCM_32[124016];
extern const u8 PCM_33[3452];
extern const u8 FM_1_01[30];
extern const u8 FM_1_02[30];
extern const u8 FM_1_03[30];
extern const u8 FM_1_04[30];
extern const u8 FM_1_05[30];
extern const u8 FM_1_06[30];
extern const u8 FM_3_01[30];
extern const u8 FM_3_02[30];
extern const u8 FM_3_03[30];
extern const u8 FM_3_04[30];
extern const u8 FM_4_01[30];
extern const u8 FM_4_02[30];
extern const u8 FM_4_03[30];
extern const u8 FM_4_04[30];
extern const u8 FM_4_05[30];
extern const u8 FM_4_06[30];
extern const u8 FM_4_07[30];
extern const u8 FM_5_01[30];
extern const u8 FM_5_02[30];
extern const u8 FM_5_03[30];
extern const u8 FM_5_04[30];
extern const u8 FM_5_05[30];
extern const u8 FM_5_06[30];
extern const u8 FM_5_07[30];
extern const u8 FM_5_08[30];
extern const u8 FM_5_09[30];
extern const u8 FM_5_10[30];
extern const u8 FM_6_01[30];
extern const u8 FM_6_02[30];
extern const u8 FM_6_03[30];
extern const u8 FM_6_04[30];
extern const u8 FM_6_05[30];
extern const u8 FM_6_06[30];
extern const u8 FM_6_07[30];
extern const u8 FM_6_08[30];
extern const u8 FM_6_09[30];
extern const u8 FM_6_10[30];
extern const u8 FM_7_01[30];
extern const u8 FM_7_02[30];
extern const u8 FM_7_03[30];
extern const u8 FM_8_01[30];
extern const u8 FM_8_02[30];
extern const u8 FM_8_03[30];
extern const u8 FM_8_04[30];
extern const u8 FM_9_01[30];
extern const u8 FM_9_02[30];
extern const u8 FM_9_03[30];
extern const u8 FM_9_04[30];
extern const u8 FM_9_05[30];
extern const u8 FM_9_06[30];
extern const u8 FM_9_07[30];
extern const u8 FM_10_01[30];
extern const u8 FM_10_02[30];
extern const u8 FM_10_03[30];
extern const u8 FM_11_01[30];
extern const u8 FM_11_02[30];
extern const u8 FM_11_03[30];
extern const u8 FM_11_04[30];
extern const u8 FM_11_05[30];
extern const u8 FM_12_01[30];
extern const u8 FM_12_02[30];
extern const u8 FM_12_03[30];
extern const u8 FM_12_04[30];
extern const u8 FM_13_01[30];
extern const u8 FM_13_02[30];
extern const u8 FM_13_03[30];
extern const u8 FM_14_01[30];
extern const u8 FM_14_02[30];
extern const u8 FM_14_03[30];
extern const u8 DAC_1_01[16868];
extern const u8 DAC_1_02[2196];
extern const u8 DAC_1_03[1524];
extern const u8 DAC_1_04[1974];
extern const u8 DAC_1_05[1776];
extern const u8 DAC_1_06[2546];
extern const u8 DAC_1_07[2266];
extern const u8 DAC_1_08[3190];
extern const u8 DAC_1_09[29652];
extern const u8 DAC_1_10[2920];
extern const u8 DAC_1_11[9496];
extern const u8 DAC_4_01[2100];
extern const u8 DAC_4_02[3800];
extern const u8 DAC_4_03[552];
extern const u8 DAC_5_01[6752];
extern const u8 DAC_5_02[1228];
extern const u8 DAC_5_03[1288];
extern const u8 DAC_5_04[1826];
extern const u8 DAC_5_05[776];
extern const u8 DAC_5_06[1720];
extern const u8 DAC_6_01[724];
extern const u8 DAC_6_02[2330];
extern const u8 DAC_7_01[218];
extern const u8 DAC_7_02[476];
extern const u8 DAC_7_03[658];
extern const u8 DAC_8_01[604];
extern const u8 DAC_8_02[2512];
extern const u8 DAC_8_03[252];
extern const u8 DAC_8_04[786];
extern const u8 DAC_11_01[1714];
extern const u8 DAC_11_02[4074];
extern const u8 DAC_11_03[2178];
extern const u8 DAC_11_04[528];
extern const u8 DAC_11_05[2554];
extern const u8 DAC_12_01[2294];
extern const u8 DAC_13_01[786];
extern const u8 DAC_13_02[316];
extern const u8 DAC_13_03[894];
extern const u8 DAC_14_01[740];
extern const u8 DAC_14_02[576];
extern const u8 DAC_14_03[1980];

#endif // _MUSRES_H_
Lastly, project file directory structure and DL of current state of project

Thanks in advance for the help! After correcting these errors, my Echo driver should be fully functional
SGDK homebrew dev and Unity3D Indie dev.
Sega does what Nintendont!
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

To be honest i am not very familiar with the Echo sound driver but it looks like you did things correctly :
Declaring all Echo resources as BINARY resources in a .res file and accessing them afterward.

I think the problem comes from your project directory structure.
Actually if you want t use the makefile.gen provided with SGDK sources tree you have to respect the SGDK folder structure :
https://code.google.com/p/sgdk/wiki/HowToUseSGDK

Basically you should have only :
- src (source folder, .c, .s, .s80 files)
- inc (header folder, .h files)
- res (resource folder, .res files)

If you respect this structure then the makefile you generate everything for you (yon don't have to manually use the rescomp tool).
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

I don't see the file that actually HOLDS THE DATA. There should be either a C file with arrays of actual bytes of data, or an s file with lists of bytes of data, or at least a bunch of incbin directives. You have REFERENCES to the data, but no data above.
MrTamk1s
Very interested
Posts: 75
Joined: Sun Jan 04, 2015 10:27 pm
Location: Pennsylvania
Contact:

Got it working!

Post by MrTamk1s »

or an s file with lists of bytes of data
There is a .s file; I forgot to show it in the directory screenshot
I think the problem comes from your project directory structure.
Actually if you want to use the makefile.gen provided with SGDK sources tree you have to respect the SGDK folder structure :
https://code.google.com/p/sgdk/wiki/HowToUseSGDK

Basically you should have only :
- src (source folder, .c, .s, .s80 files)
- inc (header folder, .h files)
- res (resource folder, .res files)

If you respect this structure then the makefile you generate everything for you (you don't have to manually use the rescomp tool).
Ah, I forgot about the inc directory! I moved all of the .h files into the inc directory, compiled the .res file manually (in order to create a .h and .s file), and then moved the .s file into the root of src, which fixed the Undefined reference problems.

New Directory structure
Echo now works! Thanks
SGDK homebrew dev and Unity3D Indie dev.
Sega does what Nintendont!
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Ah, I forgot about the inc directory! I moved all of the .h files into the inc directory, compiled the .res file manually (in order to create a .h and .s file), and then moved the .s file into the root of src, which fixed the Undefined reference problems.
You don't even have to compile it manually and move the resulting .s files to the src folder: if your .res file is in the res folder then the SGDK makefile will call rescomp for you to generate and compile the generated .s files.
Post Reply