日期:2014-05-16  浏览次数:20810 次

dlerror()函数返回错误出现错误
SingleTagIdentify= (short (*)(HANDLE hCom, unsigned int TagType, UBY TE *value))dlsym(handle,"SingleTagIdentify");
  if(dlerror()!=NULL)
  {
  const char* err=dlerror();
  cerr<<"cannot open"<<err<<endl; 
  dlclose(handle);
  cout<<"SingleTagIdentify error";
  return 0;
  }
运行结果是:cannot openSingleTagIdentify error
我再修改一下代码“cerr<<"cannot open"<<err<<endl;”改成“ cerr<<"cannot open"<<endl;“
运行结果是:cannot open
  SingleTagIdentify error
很明显第一个代码没有换行;第二个代码换行了,所以问题出现在“err”上面,这是为什么呢?[color=#FF0000][/color]

------解决方案--------------------
dlerror()
Get dynamic loading diagnostic information

Description:
The dlerror() function returns a NULL-terminated string (with no trailing newline) describing the last error that occurred during a call to one of the dl*() functions. If no errors have occurred, dlerror() returns NULL

你的dlerror调用了两次,即使第一次有错误,也不代表第二次也有错误。
估计你的本意是判断第一次的dlerror是否有错,这样的话,你应该改一下代码:
const char *err = NULL;
if((err=dlerror())!=NULL)
{
//const char* err=dlerror();
cerr<<"cannot open"<<err<<endl; 
dlclose(handle);
cout<<"SingleTagIdentify error";
return 0;
}