Originally Posted by
Niara
dev-cpp (/w mingw) allows you to create your own dll's, then on compiling it will create de dll plus the *.a library (in other compilers is a *.lib file); then simply create an *.h file and dllimport in it the dll functions names. similarly you can create static libraries that dev-cpp will compile to *.a, but here I'm not sure if you have to work with the *.def file (also created by the compiler) to import the functions, or maybe you can do it easilly like in dll's.
niara
That's just way too much information for a simple question. For libraries, you can work with them the same way you would work with a .cpp source file. If you create an instance of a class or declare a global variable, you'd have to extern that variable in order to use it in another source. Most of the time, you wouldn't need to do this, anyway. Libraries are best used for classes, structures, functions and macros that you'll want to use in your source code but you don't want to clutter the code.
An important thing to know is to define the whole code in an #ifndef so that you don't end up redeclaring the same classes incase you end up including libraries twice.
Here's a quick example of a library and a CPP coordinating:
slylib.h
Code:
/* This is our library */
#IFNDEF SLYLIB_H
#DEFINE SLYLIB_H
class foo {
public:
foo();
int foobar();
private:
int bar;
int baz;
};
foo::foo() {
bar = 10;
baz = 5
}
int foo::foobar() {
return bar + baz;
}
#ENDIF
main.cpp
Code:
/* This is our source file */
#include <iostream>
#include "slylib.h" /* Everything in my library can now be used */
int main() {
foo exmpl;
std::cout << exmpl.foobar();
return 0;
}
Oh and by the way... this is C++ but it's the same idea for C.