473,505 Members | 14,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2499
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
2585
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
3376
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
2586
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
2686
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
14832
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
3373
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
1162
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
2530
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
3259
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
7216
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
7303
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
7367
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...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.