473,246 Members | 1,544 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,246 software developers and data experts.

Creating a shared library and loading it

Hi ,

I am trying to create a shared library and trying to load it
usinf dlopen() function . My code and steps to create and load the *.so
is :

/*** test.c ***/
#include <stdio.h>
void test()
{
printf("Hello World\n");
}

/*** Steps for *.so creation ***/
bash-3.00# gcc -fPIC -c test.c
bash-3.00# gcc -o library.so -shared source.o
bash-3.00# gcc -o library.so -Wl,-h,library.so -shared source.o

/***load.c***/
#include <stdio.h>
#include <dlfcn.h>

int main(int argc,char **argv)
{
void *handle;
char *error;

handle = dlopen ("library.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}

}

/*** Steps for creating load executable***/
bash-3.00# gcc test.c -ldl

When I run the "a.out" it gives me the following error

bash-3.00# ./a.out
ld.so.1: a.out: fatal: library.so: open failed: No such file or
directory

Can someone tell me .. where I am wrong ?

Thanks !

Aug 26 '06 #1
3 2483
ab*****@gmail.com wrote:
Hi ,

I am trying to create a shared library and trying to load it
usinf dlopen() function . My code and steps to create and load the *.so
is :

/*** test.c ***/
#include <stdio.h>
void test()
{
printf("Hello World\n");
}

/*** Steps for *.so creation ***/
bash-3.00# gcc -fPIC -c test.c
bash-3.00# gcc -o library.so -shared source.o
bash-3.00# gcc -o library.so -Wl,-h,library.so -shared source.o

/***load.c***/
#include <stdio.h>
#include <dlfcn.h>

int main(int argc,char **argv)
{
void *handle;
char *error;

handle = dlopen ("library.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}

}

/*** Steps for creating load executable***/
bash-3.00# gcc test.c -ldl

When I run the "a.out" it gives me the following error

bash-3.00# ./a.out
ld.so.1: a.out: fatal: library.so: open failed: No such file or
directory

Can someone tell me .. where I am wrong ?
You are wrong in posting here about it. Here we only
deal with standard C and things like dlfcn.h , dlopen()
etc. are not part of standard C. You should ask the
question at comp.unix.programmer or
comp.os.linux.development.apps

Spiros Bousbouras

Aug 26 '06 #2
ab*****@gmail.com wrote:
/*** Steps for *.so creation ***/
bash-3.00# gcc -fPIC -c test.c
bash-3.00# gcc -o library.so -shared source.o
bash-3.00# gcc -o library.so -Wl,-h,library.so -shared source.o
/*** Steps for creating load executable***/
bash-3.00# gcc test.c -ldl
I assume you meant to compile load.c here...
>
When I run the "a.out" it gives me the following error

bash-3.00# ./a.out
ld.so.1: a.out: fatal: library.so: open failed: No such file or
directory

Can someone tell me .. where I am wrong ?
You should either specify "./library.so" in load.c, or
set LD_LIBRARY_PATH. (At least, that works on
Linux...since dlopen() is not standard C, we are already
OT, and this thread really belongs on a different NG).
For example:

[tmp]$ export LD_LIBRARY_PATH=
[tmp]$ ./a.out
library.so: cannot open shared object file: No such file or directory
[tmp]$ export LD_LIBRARY_PATH=.
[tmp]$ ./a.out
[tmp]$


Stylistically, it's a bit odd to have a file called library.so, since
that implies that the library's name is "rary". The usual
naming convention is libNAME.so.

Aug 26 '06 #3

Bill Pursell wrote:
ab*****@gmail.com wrote:
/*** Steps for *.so creation ***/
bash-3.00# gcc -fPIC -c test.c
bash-3.00# gcc -o library.so -shared source.o
bash-3.00# gcc -o library.so -Wl,-h,library.so -shared source.o
/*** Steps for creating load executable***/
bash-3.00# gcc test.c -ldl

I assume you meant to compile load.c here...

When I run the "a.out" it gives me the following error

bash-3.00# ./a.out
ld.so.1: a.out: fatal: library.so: open failed: No such file or
directory

Can someone tell me .. where I am wrong ?

You should either specify "./library.so" in load.c, or
set LD_LIBRARY_PATH. (At least, that works on
Linux...since dlopen() is not standard C, we are already
OT, and this thread really belongs on a different NG).
For example:

[tmp]$ export LD_LIBRARY_PATH=
[tmp]$ ./a.out
library.so: cannot open shared object file: No such file or directory
[tmp]$ export LD_LIBRARY_PATH=.
[tmp]$ ./a.out
[tmp]$


Stylistically, it's a bit odd to have a file called library.so, since
that implies that the library's name is "rary". The usual
naming convention is libNAME.so.
Thanks Bill . It worked :- )

Aug 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Francisco Miguel Montenegro Montes | last post by:
Hi, perhaps some of you can help me... I'm installing Python 2.3 (in Linux RedHat 8.0) and I need to build it like a shared library, because I want to interact Python with PostgreSQL. Following...
2
by: Douglass Turner | last post by:
Hi, Please release me from my own private hell. Platform: SuSE 8.1 I'm installing python 2.3 tarball as follows: ../configure --enable-shared make
3
by: Rickard Lind | last post by:
Is there any way to build the python executable statically and still be able to load modules built as shared libraries? I'm trying to run python scripts on a stripped down FreeBSD (4.9) machine...
2
by: Brad Wood | last post by:
Using VS2003, I can't add an existing class to a project w/o the IDE creating a copy of it. I want multiple projects to be able to share a central copy of a class. I can't compile the shared...
6
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. -...
7
by: akennis | last post by:
First of all, sorry for duplicating this post. I put it up in the alt.comp.lang.learn.c-c++ mistakenly. I'm investigating a problem whereby exceptions thrown from functions in a Shared Library...
0
by: abhi147 | last post by:
Hi , I am trying to create a shared library and trying to load it usinf dlopen() function . My code and steps to create and load the *.so is : /*** test.c ***/ #include <stdio.h> void...
3
by: ragi | last post by:
Hi Friends, Could you please tell me about, 1. What a shared library in c contains 2. (.a) file extension for shared libraries. 3. Is shared libraries are reentrant. Thanking you in...
3
by: Bala | last post by:
Hello, I am trying to create a shared library on solaris. The inputs to this library is a source file and then 2 static libraries. I need to call code within the shared library in another...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.