![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Loading shared libraries - dlopen unknown reference - dlfcn not working?Hi,
Just learnign on working with dll's and shared libraries... I've successfully got it complied into the dll ( im working on windows XP at the moment wiht MinGW)... However i cannot seem to load that dll. I'm trying to load it dynamically through code and not at compile time..... by default my system didn't have dlfcn in its libraries... so i downloaded it from http://code.google.com/p/dlfcn-win32/downloads/list - both the non source code ones havent worked. I've coppied the dll's and .a files etc into the respective directories at c:\MinGW where MinGW is installed. I know for a fact that its my path etc. Unfortunately neither of the two downloads work. At the moment I havent been able to compile the source from scratch because it uses Make.... and im following the trail of "<whatever> is not a recognised command" output etc....... so it might take a while for me to use that option. My code and output from the compile is below...... but if anyone can suggest a method by which I can get the dlfcn library installed? - thanks heres my code: CPP / C++ / C Code:
I'm musing Scons as the build system, but its the same when i manually go "g++ main.cpp -ldl" it doesnt work either... Code:
|
|||
|
#2
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?Quote:
Try the following:
Code:
Quote:
What happens when you execute the following from a command line? Quote:
The "-v" tells g++ to show you the paths where it is looking for stuff. If it looks in the directory where you have libdl.a but still gives the error messages, that means that the library against which the downloaded files were compiled are not compatible with your installation, so you will have to download the source for dlfcn and compile it. Regards, Dave Footnote: Are you using MinGW "barefoot" or are you using dev-cpp? |
|
#3
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?Thanks for the fast reply....
I did as you said ( actually jsut used the one i downloaded earlier which is the same one...)... the output of the first command is the same...... and g++ -v ,ain.cpp -ldl spits out errors.... and the last few of them are the dlopen errors etc. MinGW "barefoot" ??? I simply installed it. Im not using it with an IDE or anything...... most of my code edited in either notepad notepad++. As I think i mentioned.. im using SCons as the build system instead of make...... so if theres anythign i can change there what would that be? Thanks again. P.S. - if I provide the versions of MinGW I installed is it possible to find this precompiled for that version? Thanks |
|
#4
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?Quote:
Quote:
Let's try this: If you haven't done it already, download the source tarball: dlfcn-win32-r8.tar.bz2 and untar it cd into the dlfcn-win32-r8 directory. Open your text editor and paste the following Code:
If your installation is at C:\MinGW, then change the prefix line to Code:
Save the file as "config.mak" Now, enter the following from a command line: Code:
Here's what I see after the "make" command: Code:
Code:
Here's what I see Code:
Next, enter Code:
I see Code:
If everything has gone OK up to here, you now have "test.exe" in that directory. Finally Code:
I see Code:
Not that that last message (Could not get symbol from global handle...) is expected. If it works, then make sure there aren't any other versions of libdl.a and dlfcn.h in your mingw directory tree. Then you can copy libdl.a to your mingw lib directory and copy dlfcn.h to the mingw include directory, or you can enter the following Code:
Regards, Dave Footnote: I recommend you go through the way to make test.exe that I showed, using libdl.a. If you want to make libdll.dll instead of (or in addition to) libdll.a, then in config.mak, change "BUILD_STATIC=yes" to "BUILD_STATIC=no" and change "BUILD_SHARED=no" to "BUILD_SHARED=yes" Then Code:
Note that I have tested libdl.a created in the first part, but I have not tested libdll.dll. |
|
#5
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?ok.....
Firstly - I had no idea about making the config.mak ( I've never used make otehr than a few builds on ubuntu)... so that got a long way.. 1) I edited the PREFIX value to C:\MinGW 2) C:\dlfcn>make clean rm -f dlfcn.o libdl.dll libdl.a libdl.def libdl.dll.a libdl.lib libdl.exp test.e xe testdll.dll process_begin: CreateProcess((null), rm -f dlfcn.o libdl.dll libdl.a libdl.def l ibdl.dll.a libdl.lib libdl.exp test.exe testdll.dll, ...) failed. make (e=2): The system cannot find the file specified. make: *** [clean] Error 2 3) make worked: but didnt the second time I went through ( I had to wipe the directory so i assume it looked for files that were there or something?) ...... but i continued with the rest of the commands 4) make testdll.dll worked with the same output 5) make test.exe did work - but did not run: C:\dlfcn>test Opened library globally: 64A80000 Got global handle: 00400000 Got symbol from library handle: 64A81180 Hello, world! Got symbol from global handle: 64A81180 Hello, world! ---- then "test.exe has stopped responding and needs to close" windows dialog box ( god i hate those!!! lol) 6) make install because it says "A file or direct or C:\MinGW\Lib already exists"... so i assume it cant "append" as opposed to "write" to that directory? - ill i just copied across. 7) - I copied across the libdl.a file... and went to my project: g++ main.cpp -ldl says it cannot find ldl however when i run that command again AFTER running g++ main.cpp then it works: anyway - neither the with or without "-ldl" commands work - both still telling me that dlopen is a n undefined reference. Thanks for your help..... |
|
#6
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?Quote:
Quote:
Quote:
Please follow these steps exactly: OK, let's start all over again. I'll go step-by-step. The following is on a Windows XP machine. Here's the new drill:
If you see anything else at any of these steps, show me exactly what your system is telling you. Regards, Dave Footnote: If you do get to the end and test1 executes, then do the following Code:
Then I executed test2 and I saw Code:
Now, if this works, please tell me, and I may be able to tell you how to get it to work with your C++ program. |
|
#7
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?Quote:
There are various versions of the dlfcn stuff floating around. Some compiler distributions have some version of libdl.a already included. I just wanted to make absolutely certain that you can compile the C test program from current dlfcn source and get correct (and consistent) results with your compiler. If you get correct output from the test.c supplied with the dlfcn stuff, there is a very minor change that you will need to make to get it to be usable with C++ programs. (At least it works for me.) Regards, Dave |
|
#8
|
|||
|
|||
Re: loading shared libraries - dlopen unknown reference - dlfcn not working?Quote:
Once you can are absolutely sure that your results with C programs using libdl.a are correct, then here's what you need to do to make libdl.a usable with C++ programs: You will not recompile libdl.a It works. Leave it alone; leave it where it is (in the MinGW\lib directory) Make the following changes to dlfcn.h: Find the #ifndef statement CPP / C++ / C Code:
Add three lines following these so that you have: CPP / C++ / C Code:
Then at the bottom of the file: CPP / C++ / C Code:
Add three lines before this, so that now you have: CPP / C++ / C Code:
Make sure that this replaces dlfcn.h in your Mingw\include directory and that you don't have any other dlfcn.h files sprinkled around the landscape. Now in any C program that uses libdl.a, you include this file. The program can be linked with libdl.a by putting "-ldl" on the command line. In any C++ program that uses libdl.a, you include this file. The program can be linked with libdl.a by putting "-ldl" on the command line. That's all. Regards, Dave Footnote: The identifier __cplusplus works with GNU compilers and is defined if you use g++ but it is not defined if you use gcc. That means that it the extra lines have no effect on C programs but for C++ programs it tells the compiler to use the symbol names as created by the C compiler. |
|
#9
|
|||
|
|||
Re: Loading shared libraries - dlopen unknown reference - dlfcn not working?Hey,
Short answer: - its workign thanks - your brilliant! ok. I had played so much with rewriting files in minGW directoyr that i decided to reinstall MinGW ( same directory same installer. etc). Anyway - I then completed your second set of instructions. Got duplicate output ( except the what I assume is the memory locations after some output in test.exe, thus mine was of course different). Copied files across and test2.exe worked. I then rewrite the dlfcn.h file with the __cplusplus addition and its all working on my project - so thanks! Since you seem pretty knowledgable about this area of C++, once i want to go and distribute this to friends etc, do I have to package any of the dlfcn stuff into my installer and have it in my lib directory - or whats the deal? (New to C++ but definately not to programming so basic helloworld stuff isnt where I'm lingering on learning Thanks |
|
#10
|
|||
|
|||
Re: Loading shared libraries - dlopen unknown reference - dlfcn not working?Quote:
Quote:
The only real change in dlfcn distribution is to put the extern "C" lines in dlfcn.h. According to the comments in the source files (*.c and *.h) they licensed under the Gnu Public License (GPL). That means that you can modify the files any way that you want, and you can use and you can distribute the modified files as long as you don't delete anything about the copyright/license. That is, you can't remove the provisions of GPL and make it have some less-restrictive type of license (you can't put it in the public domain), and you can't make it have some more-restrictive type of license (you can't make it proprietary). Bottom line: You can change the program part of the contents, and you can add comments, but do not delete the existing comments. Furthermore, anyone who gets your modified file can distribute it (with or without further modifications) as long as it remains GPL. Regards, Dave Footnote: The Makefiles and config.mak that I posted here were written by me, and there are no copyright or license issues. I probably should have put in a comment that it is released to the public domain or some such thing. Anyhow, people are free to use anything that I write and post on this forum in any way that they want. |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shared Libraries with qmake and Exception Handling | PiJ | C++ Forum | 3 | 18-Dec-2007 10:29 |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 11:13 |
| gnu.linkonce undefined reference | newbie06 | C++ Forum | 4 | 13-Mar-2007 10:53 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The