All pastes #792910 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-21 20:25 UTC
rendered paste body
-------------- foo.h --------------------

#ifndef FOO_H_SEEN
#define FOO_H_SEEN

void foo( void );

#endif // FOO_H_SEEN


-------------- foo.c -------------------

#include "foo.h"

#include <stdio.h>

void foo( void ) {
    printf( "Hello, World!\n" );
}

--------------- build lib with: -----------

g++ -o foo.o -c foo.c -fPIC
g++ -o libfoo.so foo.o -shared

---------------- footest.c --------------

#include <foo.h>

int
main( void ) {
    foo();
    return 0;
}

---------------- build and link dynamically --------

g++ -o footest footest.c -lfoo

... whoopsy, we forgot the include path:

g++ -o footest footest.c -lfoo -I.

... dammit, forgot the library path, too:

g++ -o footest footest.c -lfoo -I. -L.

------------ run --------------------------

./footest

.... FUCK! Can't find shared library... well, we're in a non-standard directory. So:

LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./footest

------------------- output ------------------

Hello, World!