GP2X Making Libs.


MadDog

Member
Joined
Mar 4, 2006
Messages
262
Age
55
Location
UK
Website
www.maddoggames.com
So how does one make a lib with gcc, i've looked at the online docs and can't find the wood for the trees. Is is as simple as namng the output file as libMYLIB.a ???

Thanks.
 
MadDog posted on May 1 2006 at 08:50 PM said:
So how does one make a lib with gcc, i've looked at the online docs and can't find the wood for the trees. Is is as simple as namng the output file as libMYLIB.a ???
I haven't tried it myself yet, but when I was looking into it, one of the links that made the most sense to me was the following: http://www.tldp.org/HOWTO/Program-Library-...-libraries.html

I think this method is geared towards creating '.so' files using the GCC linker. If you want to create '.a' files for static linking, I think you need to use the 'ar' (or 'arm-linux-ar') archive command, which will archive object files into a single '.a' file.

What development environment are you using?
 
Last edited by a moderator:
Last edited by a moderator:
easy, when you only have a single .c then a single .o is enough. if you have multiple .c then compilen them to o. and use the tools 'ar' and 'ranlib'. use something like the following in your makefile:

Code:
$(AR) cru $(LIBFILE) $(LIB_OBJ)
$(RANLIB) $(LIBFILE)
 
I've created an archive that works. I called the output file "libK9.a" I called it this as I thought gcc lib files had to begin with lib and end in .a

Trying to include the lib with the -l command on the linker does not work. Specifying as just a input file works.

Should I worry about this or is an 'archive' different to a lib file, I thought that they were the same thing.

I'm a bit confused :huh:


P.s. I'm not using a make file.
 
MadDog posted on May 2 2006 at 10:20 AM said:
I've created an archive that works. I called the output file "libK9.a" I called it this as I thought gcc lib files had to begin with lib and end in .a

Trying to include the lib with the -l command on the linker does not work. Specifying as just a input file works.

Should I worry about this or is an 'archive' different to a lib file, I thought that they were the same thing.

I'm a bit confused :huh:


P.s. I'm not using a make file.
As long as you only have one source file, that approach is fine, but don't bother giving it a .a extension, just use .o. The -l command won't work because that specifically tells it to look for archives, which you didn't build. Those are built as a post-processing step using ar and ranlib, as a previous poster mentioned.

Strictly speaking, an 'archive' as made by ar is just a collection of files bundled into a single file. A 'lib' is an archive with extra information in it about the object modules. That extra information is generated by ranlib.

As long as you get your stuff to link and run properly, whatever you do is fine. but if you show somebody else your build script that includes a line like 'gcc -o libtest.a test.c' somebody might laugh. :p
 
Last edited by a moderator:
I got it working, my mistake was trying to add the file with its path. But now i have

-LC:\GP2X\projects\K9\lib\gp2x\debug and -lK9 on its params and works a treat. :)
 
Back
Top