Dlsym Error Undefined Symbol
Contents |
the shared library without any trouble. But dysym() can't seem to find any of its symbols. For reference, the code for the shared library is:
Dlsym Undefined Reference
1
2
3
4
5
6
#include
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include
Symbol Lookup Error Undefined Symbol Dlsym
2
3
4
5
6
7
8
9
10
11
w _Jv_RegisterClasses 000004ac T testFunction() 000016c0 A __bss_start w __cxa_finalize w __gmon_start__ U __gxx_personality_v0 000016c0 A _edata 000016c4 A _end 00000514 T _fini 0000039c T _init U puts And, oh look, second line down is testFunction! So I guess I'm asking, is there anything glaringly obvious that I'm missing? It's such a simple piece of code, so I think I must be giving the compiler the wrong info... Thanks in advance to anyone who drops by with ideas. ~Alice Oct 30, 2008 at 4:32pm UTC jsmith (5804) You are trying to compile a .cpp directly into a library. I think you need a compile step and a separate link step. g++ -c -fPIC testLibrary.cpp -o testLibrary.o g++ -shared -o testLibrary.so testLibrary.o Oct 30, 2008 at 6:19pm UTC alice (4) Thanks for your reply :) I split the build up into the two stages, but still have the same problem. nm seems to say that the symbols are "export
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Dlsym Returns Null
this site About Us Learn more about Stack Overflow the company Business Learn dlsym c++ name mangling more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Rtld_default
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://www.cplusplus.com/forum/unices/5257/ error at dlsym(): ./dynlibrary: undefined symbol: method up vote 2 down vote favorite ive got an issue i am not able to solve. Looked up everything i found so far. My problem is, i create a dyn library in my programmm an want to dlopen it and dlsym a method out of that lib. It seems that dlopen works but dlsym returns me the http://stackoverflow.com/questions/20684040/error-at-dlsym-dynlibrary-undefined-symbol-method error "undefined symbol: method" where "method" is the name of the method i past to dlsym. Here is how I create the library: execl("/usr/bin/gcc", "gcc", "-fPIC", "-Wall", "-g", "-c", "userinput.c", NULL); and: execl("/usr/bin/gcc", "gcc", "-ggdb3", "-shared", "-Wl,-soname,libuserinput.so.1", "-o", "libuserinput.so.1.0", "userinput.o", "-lc", NULL); This should work as there is a library after running my code. i open the library like this: static void *my_load_dyn (const char *lib) { static void *handle; handle = dlopen ("./libuserinput.so.1.0", RTLD_NOW | RTLD_DEEPBIND); if (handle == NULL) { printf ("error at dlopen(): %s\n", dlerror ()); exit (EXIT_FAILURE); } return handle; } /* load func from dyn lib"*/ static void *my_load_func (void *handle, char *func) { void *funcptr = dlsym (handle, func); if (funcptr == NULL) { printf ("error at dlsym(): %s\n", dlerror ()); exit (EXIT_FAILURE); } return funcptr; } and call those functions like this: void *libhandle; void (*userMethod) (unsigned char *d); libhandle = my_load_dyn(LIBUSERINPUT); userMethod = my_load_func(libhandle, "testMethod"); (*userMethod)(d); EDIT: here is the code from the userinput.c: #include
Post your question and get tips & solutions from a community of 418,497 IT Pros & Developers. It's quick & easy. dlopen success, dlsym returns undefined symbol 100+ https://bytes.com/topic/c/answers/878702-dlopen-success-dlsym-returns-undefined-symbol P: 365 tvnaidu 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 http://cboard.cprogramming.com/linux-programming/145930-shared-libraries-cplusplus-name-mangling-error.html 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", error undefined 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 Post Reply Share this Question 6 Replies Expert Mod 5K+ P: 8,904 weaknessforcats Is this C or C++? C++ requires func_name be extern "C" in the shared library. Dec 18 '09 #2 error undefined symbol reply 100+ P: 365 tvnaidu This is C code only, but file names are .cpp. eventhough C code, do I need "extern "C"?. Dec 18 '09 #3 reply Expert Mod 5K+ P: 8,904 weaknessforcats 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 reply 100+ P: 365 tvnaidu 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 reply Expert Mod 5K+ P: 8,904 weaknessforcats 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 voidMyFunc(inta,intb); 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 th
Specific Boards Linux Programming shared libraries in c++ name mangling error Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: shared libraries in c++ name mangling error Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 02-11-2012 #1 mayank.gupta22 View Profile View Forum Posts Registered User Join Date Feb 2012 Posts 5 shared libraries in c++ name mangling error I am trying to create a dynamic(.so) wrapper library along mongoDB c++ driver. There is no problem with the compilation but when I test it in a C++ sample program i get the error Code: undefined symbol: _ZN5mongo18DBClientConnection15_numConne which i assume has something to do with name mangling issues. I compiled the library as Code: g++ -fPIC -shared mongoquery.cpp -I/pathto/mongodriver -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -o libmongoquery.so Here's the program I am using for testing: Code: #include