问题
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.
回答1:
Just before including allegro
, try adding this define:
#define ALLEGRO_NO_MAGIC_MAIN
Source:
http://allegro-psp.webcindario.com/
回答2:
Check out the source of crt0.c It has a definition of main that it can't see because of the name mangling "magic" that END_OF_MAIN() does.
http://www.jbox.dk/sanos/source/lib/crt0.c.html
Try putting
#define ALLEGRO_NO_MAGIC_MAIN at the start of things.
回答3:
Try changing your main
function definition to:
extern "C"
int main(int argc, char * argv[])
See if that helps things.
来源:https://stackoverflow.com/questions/8541594/undefined-reference-to-main