views:

80

answers:

2

I'm trying to use an API for a proprietary interface device on an embedded system (Freescale HCS08), and the provided files include headers (.h) and libraries (.lib). The header compiles fine with the rest of my code (standard C), but when trying to link against the library I get memory errors saying the file might be corrupted.

My understanding of libraries in C is somewhat limited as I work almost exclusively on embedded systems where magic things like stdio, files, and dlls don't exist; but would the (or any) library be platform specific? Does it contain fully (if there is any sort of level there) compiled code? Some of the other files provided are VS project files, so if it is the case that the .lib is platform-specific, it wouldn't be unexpected that linking a file meant for x86-Windows to an 8-bit compiler would fail; it could be just me.

+7  A: 

Not only is a .lib file CPU specific (there would be no way to link HCS08 code to x86 code), it is toolchain specific (CodeWarrior won't talk to SDCC, GCC/binutils won't talk to Visual Studio).

Yann Ramin
...and also OS-specific: on UNIX you have `.a` files instead of `.lib` ones.
Amadan
A: 

Yes the .lib contains compiled code so it is platform-specific. If you have the source you should be able to re-compile it to your platform.

bshields
Even with the source code, it's not always so easy. Often, source code either has dependencies or use certain platform-specific features (in C, #ifdef _WIN32_, and so on), or some compiler-specific features. I'm sure you can find some code written for gcc 2.97 that won't work with gcc 4, even on the same Linux environment for example.
Bruno
He said "proprietary", so I'll go out on a limb and say he doesn't...
Amadan
It's remotely possible I could get the source code; there shouldn't be much secret stuff in it as it's mostly a ton of functions that generate/parse serial messages, and the communications spec is well defined. Like any library, would just save me a ton of time if I don't have to reimplement everything :P
Nick T