undefined reference to `_init()'

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Panajev2001a
Posts: 100
Joined: Sat Aug 20, 2005 3:25 am

undefined reference to `_init()'

Post by Panajev2001a »

Hi guys, I am still stuck in updating my application from FW 1.50 compatible to FW 2.00 + eLoader compatible and one of the things I am trying is the trick MrBrown suggested in a thread here regarding libSDL (I am not using SDL, but the problem might be similar so I am trying to add this fix too):

Code: Select all

int SetupCallbacks();

/*  Snippet of code, till main () added on March 20, 2006

   If this flag is set to 1, the _init() function was called and all
   global/static constructors have been called. */
static int init_was_called = 0;

__attribute__ ((constructor))
void loaderInit()
{
    int kmode_is_available = &#40;sceKernelDevkitVersion&#40;&#41; < 0x02000010&#41;;

    if &#40;kmode_is_available&#41; &#123;
        /* Do nefarious kernel stuff here */
    &#125;

    init_was_called = 1;
&#125;

extern void _init&#40;void&#41;; 

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
    /* Fanjita's EBOOT loader can be configured to skip the call to _init&#40;&#41;.
       Since we need _init&#40;&#41; for C++, we check to see if _init&#40;&#41; has been
       called.  If it hasn't we call it manually, after determining whether or
       not we can access the kernel. */

    if &#40;!init_was_called&#41; &#123;
        _init&#40;&#41;;
    &#125; 

	SetupCallbacks&#40;&#41;;

Naturally this resulted in:

Code: Select all

Panajev@Panajev /usr/local/pspdev/psp/sdk/samples/IGGS_PSP
$ make
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/main.o src/main.cpp
ccache psp-gcc -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions   -c -o
 src/disablefpu.o src/disablefpu.S
bin2o -i ../gu/cube/logo.raw logo.o logo
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/point.o src/point.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/pmatrix.o src/pmatrix.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/PSP_Utils.o src/PSP_Utils.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/camera3d.o src/camera3d.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/Matrix_stack.o src/Matrix_stack.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/3dsloader.o src/3dsloader.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/ctextureP2.o src/ctextureP2.cpp
ccache psp-g++ -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -msingle-floa
t -funroll-loops -ffast-math -fsingle-precision-constant -fno-exceptions -fno-ex
ceptions -fno-rtti   -c -o src/clipper3d.o src/clipper3d.cpp
ccache psp-gcc -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons   -c -o src/valloc.o src/valloc.c
ccache psp-gcc -I. -IC&#58;/cygwin/usr/local/pspdev/psp/sdk/include -G0 -Wall -Os -m
single-float -funroll-loops -ffast-math -fsingle-precision-constant -fno-excepti
ons  -L. -LC&#58;/cygwin/usr/local/pspdev/psp/sdk/lib   src/main.o src/disablefpu.o
logo.o src/point.o src/pmatrix.o src/PSP_Utils.o src/camera3d.o src/Matrix_stack
.o src/3dsloader.o src/ctextureP2.o src/clipper3d.o src/valloc.o -lpng -lz -lint
mdloader -lgeommath -lpspgu -lstdc++ -lm -lc  -lpspdebug -lpspdisplay -lpspge -l
pspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lp
sputility -lpspuser -lpspkernel -o krondor.elf
src/main.o&#58; In function `main'&#58;
main.cpp&#58;&#40;.text+0x124&#41;&#58; undefined reference to `_init&#40;&#41;'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;krondor.elf&#93; Error 1
I am using and have always used PSPSDK with the toolchain scripts kindly developed by oopo's so I am not trying any custom+fancy toolchain set-up, just to let you know.

Is there anything I am missing ? Do you need more data that I can provide to help me with this issue ?

Thanks anyways, I hope not to keep my application stuck in FW 1.50 land forever ;).
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

Try replace the definition of _init() with this:

Code: Select all

#ifdef __cplusplus
extern "C" &#123;
#endif
extern void _init&#40;void&#41;; 
#ifdef __cplusplus
&#125;
#endif
It's required if you are using c++
Panajev2001a
Posts: 100
Joined: Sat Aug 20, 2005 3:25 am

Post by Panajev2001a »

danzel wrote:Try replace the definition of _init() with this:

Code: Select all

#ifdef __cplusplus
extern "C" &#123;
#endif
extern void _init&#40;void&#41;; 
#ifdef __cplusplus
&#125;
#endif
It's required if you are using c++
Edit: It did work, the program now links again correctly.
Post Reply