Click to See Complete Forum and Search --> : Shared Library Problems


mart_man00
10-12-2003, 04:09 PM
This part of my (C) Makefile is giving me problems:


str_case.o : str_case.c
gcc -c str_case.c
gcc -fPIC -shared -o libstr_case.so str_case.o
strings.o : str_remove.o str_replace.o str_copy.o str_move.o str_count.o \
str_insert.o str_whereis.o str_reverse.o str_match.o str_case.o
ld -o strings.o str_remove.o str_replace.o str_copy.o str_move.o \
str_count.o str_insert.o str_whereis.o str_reverse.o str_match.o \
str_case.o
gcc -fPIC -shared -o libstrings.so strings.o


Theres a bunch of litle files(like str_case), they all work fine. But hwne i try to make the big strings.o i get linked error with standard things like strlen.

What did i do wrong?

Thanks

Stuka
10-13-2003, 05:06 PM
Could you post the specific errors? I think your real issue is not with the makefile, but with the linker. Exact error messages would make it a LOT easier to pin down.

mart_man00
10-14-2003, 09:04 PM
ok, i just had to re-install, not all my backups were the greatest. I think every thing is striagh now.

Im getting this back now(new and different error)

gcc -fPIC -shared -o libstr_insert.so str_insert.o
str_insert.o(.text+0xd7):str_insert.c: undefined reference to `_insertstring'
str_insert.o(.text+0x1f0):str_insert.c: undefined reference to `_insertchar'
collect2: ld returned 1 exit status
make: *** [str_insert.o] Error 1


Nothing in my C or H file has '_insertchar' in it. Im confused

heres my Makefile if it helps

str_remove.o : str_remove.c
gcc -c str_remove.c
gcc -fPIC -shared -o libstr_remove.so str_remove.o
str_replace.o : str_replace.c
gcc -c str_replace.c
gcc -fPIC -shared -o libstr_replace.so str_replace.o
str_copy.o : str_copy.c
gcc -c str_copy.c
gcc -fPIC -shared -o libstr_copy.so str_replace.o
str_count.o : str_count.c
gcc -c str_count.c
gcc -fPIC -shared -o libstr_count.so str_count.o
str_insert.o : str_insert.c
gcc -c str_insert.c
gcc -fPIC -shared -o libstr_insert.so str_insert.o
str_move.o : str_move.c str_remove.c str_insert.c
gcc -c str_move.c str_remove.c str_insert.c
gcc -fPIC -shared -o libstr_move.so str_move.o
str_whereis.o : str_whereis.c
gcc -c str_whereis.c
gcc -fPIC -shared -o libstr_whereis.so str_whereis.o
str_reverse.o : str_reverse.c
gcc -c str_reverse.c
gcc -fPIC -shared -o libstr_reverse.so str_reverse.o
str_match.o : str_match.c
gcc -c str_match.c
gcc -fPIC -shared -o libstr_match.so str_match.o
str_case.o : str_case.c
gcc -c str_case.c
gcc -fPIC -shared -o libstr_case.so str_case.o
strings.o : str_remove.o str_replace.o str_copy.o str_move.o str_count.o \
str_insert.o str_whereis.o str_reverse.o str_match.o str_case.o
ld -o strings.o str_remove.o str_replace.o str_copy.o str_move.o \
str_count.o str_insert.o str_whereis.o str_reverse.o str_match.o \
str_case.o
gcc -fPIC -shared -o libstrings.so strings.o
.PHONY: all clean
all : str_remove.o str_replace.o str_copy.o str_count.o str_insert.o \
str_move.o str_whereis.o str_reverse.o str_match.o str_case.o strings.o
clean:
rm *.o
rm *.so

bwkaz
10-14-2003, 11:00 PM
If you're creating a libstrings.so file, wouldn't it make more sense to *not* create the individual .so files?

Or, create a separate rule for .o -> .so creation (and actually, you could then use an implicit rule to create the .o files, and just write a suffix rule for creating the .so's).

Sidestepping the issue? Probably, but hey, whatever works... ;)

I think you could probably set something like this up:

OBJS=str_remove.o str_replace.o str_copy.o str_move.o str_count.o \
str_insert.o str_whereis.o str_reverse.o str_match.o str_case.o

SHAREDOBJS=$(patsubst %.o,lib%.so,${OBJS})

all: libstrings.so

clean:
rm -f *.o *.so

.PHONY: all clean

strings.o: ${OBJS}
ld -o strings.o ${OBJS}

libstrings.so: strings.o ${SHAREDOBJS}
gcc -fPIC -shared -o libstrings.so libstrings.o

${SHAREDOBJS}: lib%.so: %.o
gcc -fPIC -shared -o $@ $<

# This last rule should create all the lib*.so files from the *.o ones,
# except for libstrings.so (because it isn't listed in SHAREDOBJS).

# It ought to work with GNU make, 3.80 and maybe older versions.

# Most versions of make know how to make .o files from .c files already,
# so I don't have rules for that.

Stuka
10-15-2003, 10:41 AM
gcc -fPIC -shared -o libstr_insert.so str_insert.o
str_insert.o(.text+0xd7):str_insert.c: undefined reference to `_insertstring'
str_insert.o(.text+0x1f0):str_insert.c: undefined reference to `_insertchar'
collect2: ld returned 1 exit status
make: *** [str_insert.o] Error 1
That's a linker error - does your str_insert code call any functions from the other files in your library? If so, you need to make sure to link them all together, rather than separately (if you just linked the other .o file with str_insert, you'd get more linker errors when you built the whole library).