1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/**************************************************
* dltest
*
**************************************************
* This code was created by Peter Harvey @ CodeByDesign.
* Released under GPL 31.JAN.99
*
* Contributions from...
* -----------------------------------------------
* Peter Harvey - pharvey@codebydesign.com
**************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ltdl.h>
char *szSyntax =
"\n" \
"**********************************************\n" \
"* unixODBC - dltest *\n" \
"**********************************************\n" \
"* Syntax *\n" \
"* *\n" \
"* dltest libName Symbol *\n" \
"* *\n" \
"* libName *\n" \
"* *\n" \
"* Full path + file name of share to test*\n" \
"* *\n" \
"* Symbol *\n" \
"* *\n" \
"* ie a function name in the share *\n" \
"* *\n" \
"* Notes *\n" \
"* *\n" \
"* This can be placed into a makefile *\n" \
"* to throw an error if test fails. *\n" \
"* *\n" \
"* If this segfaults you probably have an*\n" \
"* unresolved symbol in the lib. This is *\n" \
"* not caught since dltest started using *\n" \
"* libtool. Linux users can refer to the *\n" \
"* man page for dlopen to create a *\n" \
"* better test. *\n" \
"* *\n" \
"* *\n" \
"* Examples *\n" \
"* *\n" \
"* dltest /usr/lib/libMy.so MyFunc *\n" \
"* *\n" \
"* Please visit; *\n" \
"* *\n" \
"* http://www.unixodbc.org/ *\n" \
"* Peter Harvey *\n" \
"**********************************************\n\n";
int main( int argc, char *argv[] )
{
void *hDLL;
void (*pFunc)();
const char *pError;
if ( argc < 2 )
{
printf( szSyntax );
exit( 1 );
}
/*
* initialize libtool
*/
if ( lt_dlinit() )
{
printf( "ERROR: Failed to lt_dlinit()\n" );
exit( 1 );
}
hDLL = lt_dlopen( argv[1] );
if ( !hDLL )
{
printf( "[dltest] ERROR dlopen: %s\n", lt_dlerror() );
exit( 1 );
}
printf( "SUCCESS: Loaded %s\n", argv[1] );
if ( argc > 2 )
{
pFunc = (void (*)()) lt_dlsym( hDLL, argv[2] );
/* PAH - lt_dlerror() is not a good indicator of success */
/* if ( (pError = lt_dlerror()) != NULL ) */
if ( !pFunc )
{
if ( (pError = lt_dlerror()) != NULL )
printf( "ERROR: %s\n Could not find %s\n", pError, argv[2] );
else
printf( "ERROR: Could not find %s\n", argv[2] );
exit( 1 );
}
printf( "SUCCESS: Found %s\n", argv[2] );
}
lt_dlclose( hDLL );
return ( 0 );
}
|