#include "foo.hpp"
#include <iostream>
#include <link.h>
#include <string>

typedef Foo *FooConstructor();

int
main(int argc, char **argv)
{
    if (argc!=2) {
        std::cerr << "usage: " << argv[0] << " <shared-lib>" << std::endl;
        return 1;
    }

    void* handle = dlopen(argv[1], RTLD_LAZY | RTLD_LOCAL);
    if (!handle) {
        return 2;
    }
    FooConstructor *constructor = (FooConstructor*) dlsym(handle, "construct");
    if (!constructor) {
        dlclose(handle);
        return 3;
    }
    Foo *foo = constructor();

    foo->msg();
}
