FREE E-BOOKS
FREE E-BOOKS
FREE E-BOOKS
http://www.flazx.com/
FREE E-BOOKS
FREE E-BOOKS
FREE E-BOOKS
Tuesday, August 18, 2009
Wednesday, August 12, 2009
Use Extern function in a library (C++)
Here is an example of usage of extern function in a (Static) Library.
stw.h:
#ifdef __cplusplus
extern "C"
#endif
void show_the_world(void);
stw.cpp:
#include
#include "stw.h"
using namespace std;
extern "C" void show_the_world() {
cout << "Hello, world!\n";
}
Build the library:
$ g++ -c stw.cpp -o stw.cpp -O0 -g
$ ar rcs stw.a stw.o
Using the library from a C application:
myapp.c:
#include "stw.h"
int main() {
show_the_world();
return 0;
}
Building the C application:
$ gcc -o myapp myapp.c stw.a -lstdc++ -g -O0
$ ./myapp
Hello, world!
$
Subscribe to:
Posts (Atom)