Unable to load symbol even if it is present in .so file? [duplicate]
Unable to load symbol even if it is present in .so file? [duplicate]
This question already has an answer here:
Now, I have been trying load dynamic library for an hour,stuck at unable to load symbol,Let me show you my problem.
Here is the snippet of my code,
void *hInstLib = dlopen("libnbuVmwareTools.so",RTLD_NOW);
LoadOneFunc(hInstLib,(void **)&vmcGetDiskChangedInfoStrm_Ptr,"vmcGetDiskChangedInfoStrm");
void LoadOneFunc(void* dlHandle, void** pFunction, const char* funcName)
{
std::stringstream strStream;
*pFunction = dlsym(dlHandle, funcName);
char* dlErrStr = dlerror();
if (*pFunction == NULL || dlErrStr != NULL)
{
strStream << "Failed to load " << funcName << ". Error = " << dlErrStr << "n";
throw std::runtime_error(strStream.str().c_str());
}
}
Now, I have checked that vmcGetDiskChangedInfoStrm is present in libnbuVmwareTools.so,
And lib is loaded successfully, But,
[root@vm vmcbt]# g++ dltest.cpp -L/root/vmware/usr/openv/lib -lnbuVmwareTools
[root@vm vmcbt]# ./a.out
Successfully loaded Library
Error while dynamically loading : Failed to load vmcGetDiskChangedInfoStrm. Error = /root/vmware/usr/openv/lib/libnbuVmwareTools.so: undefined symbol: vmcGetDiskChangedInfoStrm
And when checked if symbol is present in .so file using nm -C command,
[root@vm vmcbt]# cd
[root@vm ~]# cd /root/vmware/usr/openv/lib/
[root@vm lib]# nm -C libnbuVmwareTools.so | grep vmcGetDiskChangedInfoStrm.
00000000006680bc T vmcGetDiskChangedInfoStrm(void*, int, long, char const*, char const*, char const*, char const*, std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&, bool)
I am not getting this issue, Any help on this would be greatly appreciated.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
LoadOneFunc
can you try by adding
--export-dynamic
OR -rdynamic
to the link option?– Jayesh Bhoi
Sep 22 '14 at 7:15
--export-dynamic
-rdynamic
I have updated question description, Added LoadOneFunct defination.
– heisenberg
Sep 22 '14 at 7:27
1 Answer
1
The function is defined as a C++ function (I can see that because it has argument types in the listing). So you need to figure out what the name is, probably _Z25vmcGetDiskChangedInfoStrmPvilPKcS1_S1_S1_RSt18basic_stringstreamIcSt11char_traitsIcESaIcEEb
and then look for that.
_Z25vmcGetDiskChangedInfoStrmPvilPKcS1_S1_S1_RSt18basic_stringstreamIcSt11char_traitsIcESaIcEEb
Run
nm
without the -C argument, and you'd find the proper name(though it's harder to figure out if the function is overloaded)– nos
Sep 22 '14 at 7:20
nm
or if possible, eschew C++ types in your function's signature in favour of C types and
extern "C"
it– Steve Lorimer
Sep 22 '14 at 7:25
extern "C"
@Steve: Hard to pass in a
stringstream
type then...– Mats Petersson
Sep 22 '14 at 7:34
stringstream
You were correct ,I was able to find function name defined in .so file using only nm "without -C". but there are lots of these functions, I need to load from this linker lib. Is there any other way to use the earlier function name, as I am using header file provided to me.?
– heisenberg
Sep 22 '14 at 8:13
My guess is that you are not supposed to load them manually, but link with the shared library...
– Mats Petersson
Sep 22 '14 at 8:17
Since
LoadOneFunc
does the actual loading, any reason in particular you chose not to post it?– WhozCraig
Sep 22 '14 at 7:15