Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since it looks like you're using something UNIX-y, just use <code>dlopen</code> instead of dynamically linking your driver app against the missing symbol.</p> <p>Full sequence is:</p> <ol> <li>iterate over all submitted .so library filenames somehow (maybe you have one directory with <em>studentname.so</em> or something)</li> <li>load each library</li> <li>get the entry point function</li> <li>call it</li> <li>unload library (optional, I guess)</li> </ol> <p>like so:</p> <pre><code>void *lib = dlopen(filename, RTLD_LOCAL); void *libfun = dlsym(lib, "doAction"); if (libfun == NULL) cout &lt;&lt; "student failed by not providing doAction() in " &lt;&lt; filename &lt;&lt; endl; else { void (*doAction)(void) = (void (*)(void)) libfun; // no, I can't remember the correct syntax for casting to function pointer cout &lt;&lt; "calling " &lt;&lt; filename &lt;&lt; ":doAction()" &lt;&lt; endl; doAction(); // is there some way to tell if it succeeded? cout &lt;&lt; "unloading " &lt;&lt; filename &lt;&lt; endl; dlclose(lib); } </code></pre> <p>Notes:</p> <ul> <li>if the interface is the same in each case (ie, <code>void (*)()</code>), you could make this configurable by directory name and symbol name, and it'd work for more than one test</li> <li>in fact, if the interface is NOT what you expect, the function pointer cast will do horrible things, so careful with this</li> <li>finally, if the student used C++, their function name symbol will be mangled. Tell them to declare the entry-point as <code>extern "C" void doAction()</code> to avoid that.</li> <li>the <code>RTLD_LOCAL</code> flag should stop anything in one student's library interfering with another (if you don't unload), but there are other flags it may be sensible to add <ul> <li>specifically, <code>RTLD_NOW</code> will cause <code>dlopen</code> to fail if the student lib has an unresolved external reference it can't figure out (so you can handle it gracefully, by failing them): otherwise your program may just crash when you call <code>doAction</code>.</li> </ul></li> </ul> <hr> <p>Although I think the above is <em>better</em> than the solution you're directly asking for help with, I did also find a reference to <code>dl_iterate_phdr</code> while double-checking the docs. If you're on Linux specifically, and if the <code>dl_phdr_info.dlpi_name</code> is actually the filename ... you might be able to get it that way.</p> <p>I still think it's much uglier, though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload