gcc static library binding failure
Posted: Tue Mar 31, 2015 6:32 am
First off, some specifics:
Gcc: cross compiled under Cygwin to support plain binary
Environment: freestanding/ Part of OS development
parameters to gcc: -nostdlib -nostartfiles -nostdinc
So here goes the problem:
Now that I've a minimal C library implemented I decided to create a static library. For all function call appearing in the library, I've corresponding header files. All functions in a particular header file (and corresponding .c file before creating the library) are standalone and hence make calls only to the functions available within that file only. No external calls. I compiled all the source files with -c parameter and created a static library with:
ar rcs libstatic.a *.o
This generates libstatic.a. But now whenever I try to link this library with my source files using ld, ld throws and error text+xxx: Undefined reference to xxx. This happens for all calls to function that are available in the static library. Note that, I've #include the corresponding header files that have the function definition.
That being said, if I link the object files instead of the library, everything goes well; no errors, no warnings. So I presume somehow the library is not being created as I've expected!
So, if anyone has any insight on this matter, please respond. Thank you in advance!
Gcc: cross compiled under Cygwin to support plain binary
Environment: freestanding/ Part of OS development
parameters to gcc: -nostdlib -nostartfiles -nostdinc
So here goes the problem:
Now that I've a minimal C library implemented I decided to create a static library. For all function call appearing in the library, I've corresponding header files. All functions in a particular header file (and corresponding .c file before creating the library) are standalone and hence make calls only to the functions available within that file only. No external calls. I compiled all the source files with -c parameter and created a static library with:
ar rcs libstatic.a *.o
This generates libstatic.a. But now whenever I try to link this library with my source files using ld, ld throws and error text+xxx: Undefined reference to xxx. This happens for all calls to function that are available in the static library. Note that, I've #include the corresponding header files that have the function definition.
That being said, if I link the object files instead of the library, everything goes well; no errors, no warnings. So I presume somehow the library is not being created as I've expected!
So, if anyone has any insight on this matter, please respond. Thank you in advance!