Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to 'main'

You got to love linker errors *sarcasm*. Any way, I am developing a psp game using the psp port of allegro which came with pspsdk. And after I fixed all the other undefined references this one stumps me. The full error message and makefile and code below:

Error details

1>------ Build started: Project: PSP Pong, Configuration: Debug Win32 ------
1>  psp-g++ -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o main.o main.cpp
1>  psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150  -L. -LC:/pspsdk/psp/sdk/lib   main.o -lalleg -lpspgu -lpspirkeyb -lm -lpsppower -lpspaudio -lpsprtc  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o main.elf
1>  c:/pspsdk/bin/../lib/gcc/psp/4.3.5/../../../../psp/lib/crt0.o: In function `_main':
1>  ../../../../pspsdk/src/startup/crt0.c (86) : undefined reference to `main'
1>  C:\pspsdk\bin\make: *** [main.elf] Error 1
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

MakeFile

TARGET = main
OBJS = main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PSP Pong
LIBS = -lalleg -lpspgu -lpspirkeyb -lm -lpsppower -lpspaudio -lpsprtc 
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

main.cpp

#include <allegro.h>
int main()
{

    allegro_init();
    install_mouse();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT,480,272,0,0);

    clear_bitmap(screen);
    while (!(mouse_b & 2))
    {
        poll_mouse();
        putpixel(screen,mouse_x,mouse_y,0xFFFFFFFF);
        vsync();
    }
    clear_bitmap(screen);

    return 0;
}
END_OF_MAIN();

P.S I think the linker is not talking about the main function in main.cpp but some other main but I have no clue so any advice, corrections, any thing to help me solve this will be appreciated.

like image 215
Daniel Lopez Avatar asked Dec 07 '25 03:12

Daniel Lopez


1 Answers

Just before including allegro, try adding this define:

#define ALLEGRO_NO_MAGIC_MAIN

Source:

http://allegro-psp.webcindario.com/

like image 128
loudandclear Avatar answered Dec 08 '25 17:12

loudandclear



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!