02 Jul, 2009, Silenus wrote in the 1st comment:
Votes: 0
I have been making good progress on my toy compiler but have run into a problem with dlsym which may be just due to my lack of understanding of this particular call. Some background- The LLVM toolkit JIT systems allows dlsyming when attempting to resolve function calls. The problem I am having is finding the means to dlsym into the current executible. Is there some method for doing this? I am assuming that this is some sort of compile option in g++.

Thanks in advance.
02 Jul, 2009, quixadhal wrote in the 2nd comment:
Votes: 0
Hmm, never heard anyone use "dlsym" as a verb before….

Check out the source to AFKMUD, as I know it uses dlsym to resolve command names to functions. The main idea is to use dlopen() on your own filename, then use dlsym() to resolve function names to pointers. There is also a GNU extension to do the reverse, given a function pointer, provide the symbolic name.

I believe you also have to compile using -rdynamic, and link via -rdynamic and -ldl. Not sure if you need -shared or not.
02 Jul, 2009, Silenus wrote in the 3rd comment:
Votes: 0
Thanks for the reply. I do have a tendency to get my verbs and nouns all mixed up due to my spotty education when it comes to english grammar :P(something I may try to spend the year trying to correct). I actually found another solution to my problem which I will try first. I was basically interested in the correct flags for this. The problem of course is the library in question (LLVM) does some auto discovery magic which I havent quite been able to completely trace so I am not writing the calls myself (both good and bad I guess).
02 Jul, 2009, quixadhal wrote in the 4th comment:
Votes: 0
np, hope it works for ya!

English is a rather obnoxious language anyways. That's what happens when you get Brits (Angles and Saxons), Germans, and the French all together in the same place. *grin*
02 Jul, 2009, Kline wrote in the 5th comment:
Votes: 0
Hopefully this might be of help to you. This is from a MUD I run that makes extensive use of dlopen/dlsym/etc to break things into smaller libraries that can be (re)compiled separate of the main game; much less need for hotreboot/copyover.

void *dlcall( void *lib, char *func )
{
void (*handle)();

if( (handle = dlsym(lib,func)) == NULL )
{
log_string(dlerror());
return *dler; //custom func to just handle errors/log/etc
}
else
return *handle;
}


//from included header
#define SOCIAL_LIB "/home/matt/muds/active/vortex/src/sociallib.so"
#define HELP_LIB "/home/matt/muds/active/vortex/src/helplib.so"

extern void *sociallib;
extern void *helplib;
//end include snippet

void load_libraries()
{
sh_int lib_count = 0;
void (*handle)();

if( (sociallib = dlopen(SOCIAL_LIB, RTLD_LAZY | RTLD_GLOBAL)) == NULL)
log_string(dlerror());
else
lib_count++;

if( (helplib = dlopen(HELP_LIB, RTLD_LAZY | RTLD_GLOBAL)) == NULL)
log_string(dlerror());
else
lib_count++;

xprintf_2(log_buf,"%d of %d libraries loaded successfully.",lib_count,LIB_TOTAL);
log_string(log_buf);
log_buf[0] = '\0';

handle = dlcall(sociallib,"load_socials");
(*handle)();
handle = dlcall(helplib,"load_help_table");
(*handle)();

return;
}


edit:
Sample compile output
cc -c -O2 -g -Wall   -DIMC -DIMCMERC -fpic sociallib.c
cc -o sociallib.so o/sociallib.o -lcrypt -ldl -rdynamic -L/usr/include/mysql -lmysqlclient -lm -shared
0.0/5