dlclose problem

Michael Nottebrock michaelnottebrock at gmx.net
Sat Jun 19 16:44:19 GMT 2004


On Saturday 19 June 2004 18:20, Michael Nottebrock wrote:
> Attached is a small testcase made by Frerich Raabe 

Since the mailinglist strips tarballs, here is the case uncompressed.

-- 
   ,_,   | Michael Nottebrock               | lofi at freebsd.org
 (/^ ^\) | FreeBSD - The Power to Serve     | http://www.freebsd.org
   \u/   | K Desktop Environment on FreeBSD | http://freebsd.kde.org
-------------- next part --------------
all: plugin.o dltest

clean:
	rm -f dltest plugin.o

plugin.o:
	g++ -shared -o plugin.o plugin.cc

dltest:
	g++ -Wl,--export-dynamic -o dltest dltest.cc
-------------- next part --------------
#include <dlfcn.h>

#include <iostream>

using namespace std;

int main()
{
	typedef void( *PluginFunction )();

	void *pluginHandle = dlopen( "./plugin.o", RTLD_LAZY );
	if ( !pluginHandle ) {
		cerr << dlerror() << endl;
		return 1;
	}

	PluginFunction pluginFunction = ( PluginFunction )dlsym( pluginHandle, "entry" );

	const char *error = dlerror();
	if ( error ) {
		cerr << error << endl;
		return 1;
	}

	pluginFunction();

	dlclose( pluginHandle );
}

-------------- next part --------------
#include <string>
#include <iostream>
using namespace std;

extern "C" {

void entry()
{
	static std::string s;

	s = "Hi";

	cout << "Plugin says " << s << endl;
}

}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: signature
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20040619/11eea438/attachment-0001.bin


More information about the freebsd-current mailing list