A third party provided me a static lib (.a) to link with on solaris station. I tried to compile with sunpro, and failed at link step.
I suppose the issue is coming from the compiler I use (gcc instead?) or simply its version (as the std lib provided by the compiler could change from the version expected by the library AFAIK it could leads to errors at link step).
How could I know which compiler was used to generate this lib? Is there some tools doing that? Some option in sunpro/gcc or whatever?
As an hint: I've read some time ago that compilers use different mangling conventions when generating object files (true?). Still, "nm --demangle" command line prints me well all function names from debug symbols in this static lib. How does it work ? If my assumption is ok, nm does have a way to resolve which convention is in use in a static library, isn't it? Or is it simply meaning that lib was generated by GNU gcc, as nm is a part of GNU binutils ?
I am not close to my workstation so I can't copy&paste error output from the linker (not for the moment but I could copy them in a further edit)
-
You can try the unix utility file:
file foo.ayves Baumes : I tried but I remember it only tells me that this file uses the ELF format for SPARC platform. Does sunpro generates ELF format, as GCC does? -
Is the library supposed to be a C or C++ library?
If it is a C library then name mangling can not be the problem, as there is none in C. It could be however in a wrong format. Unices used to have libraries in the a.out format but almost all newer versions switched to more powerful formats like ELF.
If it is a C++ library then name mangling can be an issue. Most compilers embed some symbols that are compiler specific into the code, so if you have a tool like nm to list the symbols you can hopefully deduce from what compiler it came.
For example g++ creates a symbol
__gxx_personality_v0
in it's libraries
-
Extract the object files from the archive then run the
stringscommand on some of them (first on the smaller ones since there'd be less noise to sift through). Many compilers insert ASCII signatures in the object files.For example, the following meaningless source file,
foo.c:extern void blah();when compiled on my Fedora 10 machine into foo.o via
gcc -c -o foo.o foo.cresults in a 647 bytefoo.oobject file. Runningstringsonfoo.oresults inGCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7) .symtab .strtab .shstrtab .text .data .bss .comment .note.GNU-stack foo.c
which makes it clear the compiler was GCC. Even if I'd compiled it with
-fno-ident, the .GNU-stack note ELF section would have still been present.You can extract the object files using the
arutility, or using Midnight Commander (which integrates ar), or you can simply runstringson the archive (which might give you more noise and be less relevant, but would still help.)Jonathan Leffler : Or just run 'strings' directly on the library - no need to extract the object files first.Mihai Limbășan : Like I mentioned, there's a lot more output, *especially* in the case of C++ object files, and it's much easier to miss compiler signatures. Also, there is no requirement that all objects in an archive be from the same compiler... -
I tend to use the
stringsprogram (with the '-a' option, or my own variant where the '-a' behaviour is standard) and look for the tell-tale signs. For example, in one of my own libraries, I find:/work1/gcc/v4.2.3/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.3/include /work1/gcc/v4.3.0/bin/../lib/gcc/sparc-sun-solaris2.10/4.3.0/include /work1/gcc/v4.3.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.3.1/include /work1/gcc/v4.3.3/bin/../lib/gcc/sparc-sun-solaris2.10/4.3.3/includeThat suggests that the code in the library has been compiled with a variety of versions of GCC over a period of years (actually, I'm quite startled to find so many versions in a single library).
Another library contains:
cg: Sun Compiler Common 11 Patch 120760-06 2006/05/26 acomp: Sun C 5.8 Patch 121015-02 2006/03/29 iropt: Sun Compiler Common 11 Patch 120760-06 2006/05/26 /compilers/v11/SUNWspro/prod/bin/cc -O -v -Xa -xarch=v9 ...So, there are usually fingerprints in the object files indicating which compiler was used. But you have to know how to look for them.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.