Including LD Custom Library
Posted: Thu Aug 14, 2008 9:45 am
Hi,
I know I've had a few toolchain issues before and I know sometimes they've been daft mistakes, but I'm afraid I'm stuck again!
I've developped a library (libos.a) which contains some useful classes and functions for the freestanding environment. This includes a string class, for example. The idea behind the (static) library is that I can use the functions in both my OS and my second stage loader with minimal effort.
The problem is this: Until this point, I have been linking with the following command line in my makefile:
Sorry about all those makefile variables, but hopefully anyone familiar with makefiles gets the gist of it! This, of course, links the entire libos.a whether the functions are used or not. So, I tried the following:
Which instead uses the libos.a file as a traditional library - only those required functions (Solar's one function per file style) are included in the final binary = smaller binaries! The only problem is that with this second method, all symbols within the library are unresolved. I know that LD is finding my library, because changing -l$(LIB) to -lrandomfile causes LD to say "cannot find -lrandomfile". LIBPATH and LIB makefile variables are also correct because the first example worked.
Removing -nostdlib does not change anything - and according to the LD docs this should make no difference to explicitly declared libraries anyway. The library is archived with ar (flags -vcrs to create an archive index as per ranlib - removing the s argument makes no difference).
Does anyone know what I have missed this time?
Cheers,
Adam
I know I've had a few toolchain issues before and I know sometimes they've been daft mistakes, but I'm afraid I'm stuck again!
I've developped a library (libos.a) which contains some useful classes and functions for the freestanding environment. This includes a string class, for example. The idea behind the (static) library is that I can use the functions in both my OS and my second stage loader with minimal effort.
The problem is this: Until this point, I have been linking with the following command line in my makefile:
Code: Select all
LDFLAGS:=-T $(SRCBASE)link.ld -nostdinc -nostdlib -o
...
@$(LD) $(LDFLAGS) $(BUILD)$(BINARY) $(OBJ) $(LIBPATH)$(LIB)
Code: Select all
LDFLAGS:=-T $(SRCBASE)link.ld -nostdinc -nostdlib -static -L$(LIBPATH) -l$(LIB) -o
...
@$(LD) $(LDFLAGS) $(BUILD)$(BINARY) $(OBJ)
Removing -nostdlib does not change anything - and according to the LD docs this should make no difference to explicitly declared libraries anyway. The library is archived with ar (flags -vcrs to create an archive index as per ranlib - removing the s argument makes no difference).
Does anyone know what I have missed this time?
Cheers,
Adam