PCallFunc=(Func_CallFunc) dlsym (pLibHandle, "CallFunc");
If (pCallFunc==NULL)
{
Sprintf (pMsg, "open the library [CallFunc] [% s] function failure. ERR: % s", pLibName, dlerror ());
return -1;
}
Here is normal, dynamic link library CallFunc function called error
The Program received signal SIGSEGV, Segmentation fault.
0 x00007fffef9393ea in CallFunc (pSrcName=& lt; Error reading variable: always access the memory at address 0 x7fffffcf4108 & gt; ,
PSrcPath=& lt; Error reading variable: always access the memory at address 0 x7fffffcf4100 & gt; ,
POutName=& lt; Error reading variable: always access the memory at address 0 x7fffffcf40f8 & gt; ,
IRecordCount=& lt; Error reading variable: always access the memory at address 0 x7fffffcf40f0 & gt; ,
PMsg=& lt; Error reading variable: always access the memory at address 0 x7fffffcf40e8 & gt;) The at PGWDecode. CPP: 54
CodePudding user response:
PLibHandle=dlopen (pLibName RTLD_LAZY);If (pLibHandle==NULL)
{
Sprintf (pMsg, "open the library [% s] failure. ERR: % s", pLibName, dlerror ());
return -1;
}
PCallFunc=(Func_CallFunc) dlsym (pLibHandle, "CallFunc");
If (pCallFunc==NULL)
{
Sprintf (pMsg, "open the library [CallFunc] [% s] function failure. ERR: % s", pLibName, dlerror ());
return -1;
}
Int ftplib: : CallLibFunc (char * pSrcName, char * pSrcPath, char * pOutName, int * iRecordCount, char * pMsg)
{
Return pCallFunc (pSrcName, pSrcPath pOutName, iRecordCount, pMsg);
}
GDB error message
Ftplib: : CallLibFunc (pSrcName=0 x7fffffff8b60 "bss96.ecld.com _DATA_TEST30_BB000000003300. Dat,"
PSrcPath=0 x7fffffff9f80 "/home/bill/data/collect/data/collect_tmp0/12155", pOutName=0 x685884 ", "iRecordCount x7fffffffa698=0,
PMsg=0 x7fffffff9980 "") at the/home/bill/src_smz/collect_multiprocess/ftplib CPP: 48
Return pCallFunc (pSrcName, pSrcPath pOutName, iRecordCount, pMsg);
The Program received signal SIGSEGV, Segmentation fault.
0 x00007fffef9393ea in CallFunc (pSrcName=& lt; Error reading variable: always access the memory at address 0 x7fffffcf4108 & gt; ,
PSrcPath=& lt; Error reading variable: always access the memory at address 0 x7fffffcf4100 & gt; ,
POutName=& lt; Error reading variable: always access the memory at address 0 x7fffffcf40f8 & gt; ,
IRecordCount=& lt; Error reading variable: always access the memory at address 0 x7fffffcf40f0 & gt; ,
PMsg=& lt; Error reading variable: always access the memory at address 0 x7fffffcf40e8 & gt;) The at PGWDecode. CPP: 54
54 {
CodePudding user response:
Looks like the problem, the key should be the callCodePudding user response:
Use GDB step through into the function, check the calling convention (parameter passing way, the number of parameters, a stack is balance, parameter types, parameter value scope,... )Calling convention https://msdn.microsoft.com/zh-cn/magazine/9b372w95.aspx
CodePudding user response:
I wrote a test program manual, there is no any business logicC
g + + - g test.
./a.out./libPGWDecode. So a.t xt. Can call normal libPGWDecode. So the dynamic link library
With our application in the paper is the error,
But our application calls the other dynamic libraries can be successful, the dynamic library has a problem, the test program code below
# include & lt; DLFCN. H>
# include & lt; String. H>
# include & lt; Stdio. H>
//initialize the library environment
PMsg Func_InitEnv typedef int (*) (char *);
//perform the conversion function
Typedef int (* Func_CallFunc) (char * pSrcName, char * pSrcPath, char * pOutName, int * iRecordCount, char * pMsg);
//release the library environment
PMsg Func_UnInitEnv typedef int (*) (char *);
Void * pLibHandle;//handle dynamic library
Func_InitEnv pInit;//initialization function handles
Func_CallFunc pCallFunc;//handle to perform function
Func_UnInitEnv pUnInit;//handle to release function
Int InitFtpLib (char * pLibName, char * pMsg)
{
PLibHandle=dlopen (pLibName RTLD_LAZY);
If (pLibHandle==NULL)
{
Sprintf (pMsg, "open the library [% s] failure. ERR: % s", pLibName, dlerror ());
return -1;
}
PInit=(Func_InitEnv) dlsym (pLibHandle, "InitEnv");
If (pInit==NULL)
{
Sprintf (pMsg, "open the library [InitEnv] [% s] function failure. ERR: % s", pLibName, dlerror ());
return -1;
}
PUnInit=(Func_InitEnv) dlsym (pLibHandle, "UnInitEnv");
If (pUnInit==NULL)
{
Sprintf (pMsg, "open the library [UnInitEnv] [% s] function failure. ERR: % s", pLibName, dlerror ());
return -1;
}
PCallFunc=(Func_CallFunc) dlsym (pLibHandle, "CallFunc");
If (pCallFunc==NULL)
{
Sprintf (pMsg, "open the library [CallFunc] [% s] function failure. ERR: % s", pLibName, dlerror ());
return -1;
}
//performs initialization
Return pInit (pMsg);
}
Int CallLibFunc (char * pSrcName, char * pSrcPath, char * pOutName, int * iRecordCount, char * pMsg)
{
Return pCallFunc (pSrcName, pSrcPath pOutName, iRecordCount, pMsg);
}
Int UnInitFtpLib (char * pMsg)
{
Return pUnInit (pMsg);
}
//char * libname, char * pSrcName, char * pSrcPath
//a.out libgetrecordnum. So GetRecordNum. CPP./
Int main (int arg c, char * * argv)
{
Char MSG [256].
Char outname [256].
int count=0;
If (arg c & lt; 3)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull