当前位置: 技术问答>linux和unix
UNIX/solaris下的共享库问题,大虾帮忙!
来源: 互联网 发布时间:2015-01-08
本文导语: test program: #include "stdio.h" #include "dlfcn.h" int main() { void *h_lib; /* Handle of shared lib */ // char *p; char file_name[10]="a.so"; /* The complete file name */ h_lib = dlopen(file_name, RTLD_LAZY); if(!h_lib) { ...
test program:
#include "stdio.h"
#include "dlfcn.h"
int main()
{
void *h_lib; /* Handle of shared lib */
// char *p;
char file_name[10]="a.so"; /* The complete file name */
h_lib = dlopen(file_name, RTLD_LAZY);
if(!h_lib)
{
printf("bad");
}
else
{
// dlclose(h_lib);
printf("The shared library--[%s] was opened successively!n",file_name);
}
return 1;
}
结果:
> gcc main.c
Undefined first referenced
symbol in file
dlopen /var/tmp/ccPXPPAr.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
请帮忙解决,究竟是怎么回事?
#include "stdio.h"
#include "dlfcn.h"
int main()
{
void *h_lib; /* Handle of shared lib */
// char *p;
char file_name[10]="a.so"; /* The complete file name */
h_lib = dlopen(file_name, RTLD_LAZY);
if(!h_lib)
{
printf("bad");
}
else
{
// dlclose(h_lib);
printf("The shared library--[%s] was opened successively!n",file_name);
}
return 1;
}
结果:
> gcc main.c
Undefined first referenced
symbol in file
dlopen /var/tmp/ccPXPPAr.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
请帮忙解决,究竟是怎么回事?
|
gcc main.c -ldl