- 论坛徽章:
- 0
|
我在SOLARIS9中用G++做的.so文件,在运行时出现如下错误:
1error[ld.so.1: lihc: fatal: pri: can't find symbol ]
shell returned 255
程序如下:
lihc.cpp:
#include "iostream"
#include "string"
#include "dlfcn.h"
#include "link.h"
#include "errno.h"
using namespace std;
int main( )
{
void *handle;
int ( *func1 )( string );
if ( ( handle = dlopen( "tld.so", RTLD_LAZY ) ) == NULL )
{
printf( "error" );
exit( -1 );
}
if ( ( func1 = ( int ( * )( string ) )dlsym( handle, "pri" ) ) == NULL )
{
printf( "1error[%s ]", dlerror() );
dlclose( handle );
exit( -1 );
}
(*func1)( "ssdfs" );
dlclose( handle );
return 0;
}
tld.cpp 如下:
#include "iostream"
#include "string"
using namespace std;
int pri( string str )
{
cout << str << endl;
return 0;
}
makefile 如下:
CC=g++
lihc:lihc.o
$(CC) -o lihc lihc.o /usr/lib/ld.so.1 -ldl -lc -lm
lihc.o:lihc.cpp
$(CC) -c lihc.cpp
tld.so:tld.o
$(CC) -G -g -o tld.so tld.o
tld.o:tld.cpp
$(CC) -c tld.cpp
co:
rm -f *.o *.so |
|