Hello C programmers,

I understand the general nature of library files, that C needs them to understand include files, that they come in many flavors (.lib, .dll, .a, .so), but I don't understand the process of taking source code X and then using it to build library file Y.

My current process is this. 1) Google around until I find someone who has already build a ".a" file for the source code I'm using. 2) Copy that file to the MinGW "lib" directory. 3) Everything is great.

Since this is really pathetic, I was hoping someone could help direct me to a better process for taking source code X and then using it to build library file Y using MinGW/GCC. I'm sure this is a really basic issue, but all the information I can find on C libraries usually looks like ar rc libutil.a util_file.o util_net.o util_math.o and involves using ".o" object files (which never come with source code) and it never explains the missing links between the source code and the library file.

Thanks!

I'm sure this is a really basic issue, but all the information I can find on C libraries usually looks like ar rc libutil.a util_file.o util_net.o util_math.o and involves using ".o" object files (which never come with source code) and it never explains the missing links between the source code and the library file.

Well, ar rc libutil.a util_file.o util_net.o util_math.o is pretty much the gist of it. You use the compiler to build .o files. If you want an executable, you build the .o s into such with a linker. If you want a library, you build the .o s into such with a librarian. gcc may also hide the linker, but ar is the librarian. Compile your .c files into .o files and make a library.

>Since this is really pathetic
Been there, done that..., found this and this.

Thank you all for your responses.

Source code always comes in a big mess of files. Usually there's an include folder and a src folder. How do you know what to make the object files from? I would assume it's the src, since all the object building examples use a .c file instead of .h file. But what if the src folder contains 20 folders with no obvious "primary" folder or file to build from.

For a perfect example, I just downloaded the FreeType library. The src folder contents are this:

10/21/2007  08:18 PM    <DIR>          autofit
10/21/2007  08:18 PM    <DIR>          base
10/21/2007  08:18 PM    <DIR>          bdf
10/21/2007  08:18 PM    <DIR>          cache
10/21/2007  08:18 PM    <DIR>          cff
10/21/2007  08:18 PM    <DIR>          cid
10/21/2007  08:18 PM    <DIR>          gxvalid
10/21/2007  08:18 PM    <DIR>          gzip
06/05/2005  12:49 AM               808 Jamfile
10/21/2007  08:18 PM    <DIR>          lzw
10/21/2007  08:18 PM    <DIR>          otvalid
10/21/2007  08:18 PM    <DIR>          pcf
10/21/2007  08:18 PM    <DIR>          pfr
10/21/2007  08:18 PM    <DIR>          psaux
10/21/2007  08:18 PM    <DIR>          pshinter
10/21/2007  08:18 PM    <DIR>          psnames
10/21/2007  08:18 PM    <DIR>          raster
10/21/2007  08:18 PM    <DIR>          sfnt
10/21/2007  08:18 PM    <DIR>          smooth
10/21/2007  08:18 PM    <DIR>          tools
10/21/2007  08:18 PM    <DIR>          truetype
10/21/2007  08:18 PM    <DIR>          type1
10/21/2007  08:18 PM    <DIR>          type42
10/21/2007  08:18 PM    <DIR>          winfonts
               2 File(s)            808 bytes
              25 Dir(s)   5,147,090,944 bytes free

How would you know where to begin? From the documentation:

How do I compile the FreeType 2 library?

The library can be compiled in various ways, and detailed documentation is available in documentation directory of the FreeType 2 source tree.

For compilation on the command line, GNU make is necessary; other build tools won't work. The source bundle also comes with project files for some graphical IDEs like Visual C; note, however, that those files are sometimes not up to date since it is contributed code not used by the core developers.

I couldn't find any "detailed documentation" in the source tree. It would seem reasonable that's there some universal way that C programmers know which files to build the object files from, but I'm totally lost. How do you know?

Go up to the parent directory > cd .. and read the README file. That probably will tell you what you need to do. There's also a make file and a configure file. Those are usually involved with compiling and installing.

Thanks for the reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.