undefined reference to '_ctype_'

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

Moderators: cheriff, TyRaNiD

Post Reply
Paddle
Posts: 5
Joined: Mon Jun 20, 2005 12:20 am

undefined reference to '_ctype_'

Post by Paddle »

I have searched and tried many things, but still having no luck, all my code compiles, but linking, well..no. I keep getting undefined reference to '_ctype_'. All of the complaints come from standard c functions.

I'm using these flags

TOP = /usr/local/pspdev/psp/psp
LIBDIR = $(TOP)/lib

PREFIX = psp
AS = $(PREFIX)-gcc
CC = $(PREFIX)-gcc
LD = $(PREFIX)-g++
RM = /bin/rm -f

CFLAGS = $(DEFINES)
ASFLAGS = -g -c -xassembler -O
LDFLAGS = -Wl,-Ttext -Wl,8900000 -L$ (LIBDIR) -lstdc++ -lm -lc -lgcc

I have tried linking using psp-gcc. Every combination of -l(lib) I can find.
Any ideas?

Cheers
User avatar
ReKleSS
Posts: 73
Joined: Sat Jun 18, 2005 12:57 pm
Location: Melbourne, Australia

Post by ReKleSS »

...why the heck is your linker (LD) set to g++? Try changing it to ld. I'm guessing that when you link you end up trying to link as a c++ program, when the libraries aren't working right...
-ReK
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

Don't use LD, if you are writing C link with gcc, if you are writing C++ link with g++.
Solves soooo many problems...
Shoot Pixels Not People!
Makeshift Development
Paddle
Posts: 5
Joined: Mon Jun 20, 2005 12:20 am

Post by Paddle »

As I stated in the post I have tried psp-gcc with no luck. I have found that these are the problem functions.

isalpha(c)
isupper(c)
islower(c)
isdigit(c)
isxdigit(c)
isspace(c)
ispunct(c)
isalnum(c)
isprint(c)
isgraph(c)
iscntrl(c)

They are all defined in ctype.h

I have tried to just paste the following in the hello world app, but can not get it to link. No matter what I try. The code that I'm am trying to compile only uses a couple of these and I can easily rewrite them. It just bugs me that I don't know why they aren't working. I will keep on trying to figure it out. If anyone has any ideas, please let me know.

if(isalpha(c)) pgFillvram(0);
if(isupper(c)) pgFillvram(0);
if(islower(c)) pgFillvram(0);
if(isdigit(c)) pgFillvram(0);
if(isxdigit(c)) pgFillvram(0);
if(isspace(c)) pgFillvram(0);
if(ispunct(c)) pgFillvram(0);
if(isalnum(c)) pgFillvram(0);
if(isprint(c)) pgFillvram(0);
if(isgraph(c)) pgFillvram(0);
if(iscntrl(c)) pgFillvram(0);

Cheers
Paddle
Posts: 5
Joined: Mon Jun 20, 2005 12:20 am

Post by Paddle »

Also any functions that use these won't link for me. Is this a limitation of the toolchain?

Adding this to HelloWorld

#include <stdlib.h>

char* number = "10";
char* bar;
long foo = strtol( number, &bar, 10);
if( foo == 10 ) pgFillvram(0);

gives

psp-gcc -O0 startup.o hellopsp.o kernel.o pg.o -Wl,-Ttext -Wl,8900000 -Wl,-L /
usr/local/pspdev/psp/psp/lib -lm -lc -lgcc -o out > HelloPSP.map
/usr/local/pspdev/psp/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(strtol.o): In
function `_strtol_r':
../../../../../newlib/libc/stdlib/strtol.c:139: undefined reference to `_ctype_'

../../../../../newlib/libc/stdlib/strtol.c:139: undefined reference to `_ctype_'

../../../../../newlib/libc/stdlib/strtol.c:186: undefined reference to `_ctype_'

../../../../../newlib/libc/stdlib/strtol.c:186: undefined reference to `_ctype_'

collect2: ld returned 1 exit status
make: *** [HelloPSP.elf] Error 1


Am I the only one getting this, has anyone else had success with these functions?

Buller...Buller...Buller...

Cheers
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

I think it has something to do with code that was commented out in newlib (the libc that ships with psptoolchain). I'm looking into it.
Paddle
Posts: 5
Joined: Mon Jun 20, 2005 12:20 am

Post by Paddle »

sweet...thanks for the response. I will also take a look there.

Cheers
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Fixed. Grab the updated patches at http://www.oopo.net/consoledev/files/ps ... 050622.tgz.
Paddle
Posts: 5
Joined: Mon Jun 20, 2005 12:20 am

Post by Paddle »

Thank you sir!

I'm curious, was removing the patch to ctype_.c all that was needed, or is the change to the toolchain.sh also significant.

Cheers
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

It was the addition of -DCOMPACT_CTYPE to the Allegrex-specific CFLAGS in newlib/configure.host that fixed it. GCC 4.0 seems to have a problem with aliases, so if COMPACT_CTYPE wasn't defined it would attempt to use an alias to point _ctype_ inside of another variable. Defining COMPACT_CTYPE caused _ctype_ to be created as an array instead.
Post Reply