|
Getting SO's to compile and load properly |
DanielH
Member #934
January 2001
|
In another thread I mentioned my Sudoku game. I'm trying to get it to work in Linux. After some lengthy effort I'm getting some errors. In the game. generator.so is loaded, but I can't extract the functions. After some work, I've made a simple test program and can't get the so to load. // yeah.cpp #include <stdio.h> int p = 0; int yeah() { printf( "%d\n", ++p ); return 0; }
Compiled with:
Compiled with: yeah.so and main are created with permissions 777. But when main is ran as So, what am I doing wrong? Any suggestions to help me. |
ReyBrujo
Moderator
January 2001
|
Set your LDPATH (or was it LD_PATH?) to point to the directory where the .so file is. Otherwise, add it to /etc/ld.so.conf (or something similar) and run ldconfig. Or run ldconfig dir/where/so/is to temporarily add it to your linker path. -- |
miran
Member #2,407
June 2002
|
No, use absolute paths! For example: char soName[] = "yeah.so" char fullName[MAX_PATH]; replace_filename(fullName, argv[0], soName, MAX_PATH); ... ReyBrujo: That's for dynamically loading plugins! EDIT: Hmm, still doesn't work. Interesting, because I use very similar code and it works... -- |
ReyBrujo
Moderator
January 2001
|
Oh, you are right. With the full path it loads the library but can't get the handle to the function. (Edited: Got it working. The problem is that the function name is mangled in C++, thus you can't just load yeah, but instead _Z4yeahv (in my case). Some magic with extern "C" should make it work. -- |
Evert
Member #794
November 2000
|
Quote: Set your LDPATH (or was it LD_PATH?) LD_LIBRARY_PATH |
miran
Member #2,407
June 2002
|
Oh I forgot he didn't have extern "C". So, final solution: 1. extern "C" in front of the functions you export -- |
DanielH
Member #934
January 2001
|
Ok I did that and the program runs fine. It wasn't loading the text correctly, but I fixed that also. I just need to compile it statically and add it to the download page. Thanks Guys |
|