This is a mirror of official site: http://jasper-net.blogspot.com/

Mingw Static and Dynamic Libraries

| Thursday, June 3, 2010
Introduction

This article is intended to give a brief and simple introduction to compiling your own libraries with MinGW (Minimal GNU for Windows) compiler. This article assumes you have a basic understanding of the C language. First thing you'll need to do is download MinGW. I strongly suggest that you set the windows environmental path to the MinGW directory. This allows you to call the MinGW GCC compiler from any directory on your computer. On Windows7 it is right click on My Computer->Properties->Advanced->Environmental Variables and add the MinGW directory to the PATH or simply type this into cmd.exe.  

>SET PATH=%PATH%;C:\MinGW\bin

SET will temporarily set your environmental variables for the duration of your command prompt session. If you would like to permanently change your environmental variables add SETx instead of SET.

The Static Library

The following code was used to create both the static and dynamic library. It is a simple example to demonstrate a possible math library.

add.c:

#include "add.h"

int add(int a, int b) {
   return a + b;
}

add.h:

#ifndef ADD_H
#define ADD_H
int add(int a, int b);
#endif  // ADD_H

The main file demonstrates how to call the library file after its compiled. Notice that you require the header file or an external reference to execute a static library. In most cases if you share your library it will be in the form of a header file. The function declaration is necessary for the linker. If you did not have access to the header file you would need to go about reverse engineering the library to create the function declarations.

Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: