473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

dlopen success, dlsym returns undefined symbol

365 100+
opening shared lib with dlopen, gets success, but dlsym returns an error saying undefined symbol, also passing "-rdynamic" during linking this shared lib, any idea?. dlopen success, dlsym gets error, also when I do nm on this shared lib, I can see symbol, this is standalone lib, not linked with executable.


if ((handle = dlopen(libname, RTLD_NOW)) == NULL) {
printf("ERROR: cannot load library: %s, %s\n", libname, dlerror());
exit(1) ;
} else {
ret = dlsym(handle, func_name);
if ((error = dlerror()) != NULL) {
printf("ERROR: load condition function(%s) failed in %s: error:%s\n",
func_name, libname, error );
exit(1);
}
}
Dec 18 '09 #1
6 18854
weaknessforcats
9,208 Expert Mod 8TB
Is this C or C++?

C++ requires func_name be extern "C" in the shared library.
Dec 18 '09 #2
tvnaidu
365 100+
This is C code only, but file names are .cpp. eventhough C code, do I need "extern "C"?.
Dec 18 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
If the file names are .cpp I expect you have a C++ compiler.

If so, you will need the extern "C" when you build the shared library OR you must change the project settings to compile the .cpp files as C code only.

I say this since most C compiles use .c for this implementation files.
Dec 18 '09 #4
tvnaidu
365 100+
Thanks, it works, now dlsym works.

but when I tried to execute the function which was in shared lib, it fails. this func1 is part of shared lib was opened above using dlopen, then dlsym gets success, execution fails?. any idea?.


(func1)(param1, param2, param3).
Dec 18 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
dlsym returns a void*. This is the address of the function in the library.

If this library function looks like:

Expand|Select|Wrap|Line Numbers
  1. void MyFunc(int a, int b);
Then you must typecast the void* returned from dlsym into a pointer to a function that takes two int arguments and returns a void.

Then you use the typecast pointer to make the call:

ret = dlsym(handle, func_name);

void (*MyPointer)(int, int) = (void (*)(int,int))ret;

MyPointer(3,4);
Dec 18 '09 #6
tvnaidu
365 100+
Thanks for your posting.
Dec 19 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Christopher Armstrong | last post by:
With the following situation, Numarray can't find Python's symbols. problematic-Python:: Main dlopens Two Two dynlinks Python Python dlopens Numarray Numarray dynlinks Python I have another...
1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
2
by: Manuel Maria Diaz Gomez | last post by:
Hi Everybody, maybe you can give me a hint about this. I implemented a simple singleton Factory that will (among other things) keep a registry of objects. Objects register themself in the...
0
by: pervinder | last post by:
Hi, I have a c++ application which depends on some other libs which uses stlport When i build the application, it works fine on sun/linux/hp platform. (provided the .a for the dependency libs) ...
3
by: Matt Churchyard | last post by:
Now I realize this is off topic, and will probably quickly receive a list of replys from people who are quicker to criticize posters than give them help but if you know of a more suitable newsgroup...
7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
2
by: Dave | last post by:
Hi all... I wrote a simple program to test the dlopen()...\ #include <dlfcn.h> int main(int argc, char **argv) { void *handle; double (*cosine)(double); char *error;
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
10
by: Unknown Soldier | last post by:
Hello, I have a program that makes use of external plugins, implemented as shared libraries loaded at runtime through a call to dlopen(). The libraries export symbols which the main program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.