C/C++ shared libraries on Linux.

This is the first time that I created a dynamic library in linux and although the program works, I do not get the correct information about the library when executing ldd.

I explain the details:

1) Source code:

bye_fn.c:
---------

#include <stdio.h>
#include "hello.h"

void bye (const char* name)
{
printf ("\n\n%s, I see you soon !\n\n", name);
}


hello_fn.c:
-----------

#include <stdio.h>
#include "hello.h"

void hello (const char* name)
{
printf ("\n\nHello, %s !\n\n", name);
}


hello.c:
--------

#include "hello.h"
#include <stdio.h>

int main (void)
{
hello ("José");
printf ("Please to meet you. You will work with us. You start next week. Congratulations !\n");
bye ("José");

return 0;
}


2) Steps followed to obtain the shared library and the executable program:

gcc -fPIC -Wall -c hello_fn.c

gcc -fPIC -Wall -c bye_fn.c

gcc -shared -Wall -o libhello.so hello_fn.o bye_fn.o

gcc hello.c libhello.so -o hello


3) Steps followed to execute the "hello" program:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./

./hello

It works right.


4) My question:

If I execute the command: ldd hello
the output is:

linux-vdso.so.1 => (0x00007ffc1db7c000)
libhello.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007eff63dd2000)
/lib64/ld-linux-x86-64.so.2 (0x00007eff6419b000)

I would to get correctly the information about the library "libhello.so" that is being used by "hello".

What should I change or add in the steps described in point 2, to achieve this?

Last edited on
It's just the LD_LIBRARY_PATH that's badly specified.

Instead of this:
 
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./


use this:
 
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:`pwd`
Here you have used wrong step in programming likes printf ("\n\n%s, I see you soon !\n\n", name) because if you want to print to char name them it can not produce the correct values which is shown as in your given hello ("José");
printf ("Please to meet you. You will work with us. You start next week. Congratulations !\n");

show here i want to inform that first you clear mistakes to find good and accurate result.



#include <stdio.h>
#include "hello.h"

void bye (const char* name)
{
printf ("\n\n%s, I see you soon !\n\n", name);
}


hello_fn.c:
-----------

#include <stdio.h>
#include "hello.h"

void hello (const char* name)
{
printf ("\n\nHello, %s !\n\n", name);
}


hello.c:
--------

#include "hello.h"
#include <stdio.h>

int main (void)
{
hello ("José");
printf ("Please to meet you. You will work with us. You start next week. Congratulations !\n");
bye ("José");

return 0;
}


For more visit:- http://www.traininginlucknow.in/best-c-language-training-in-Lucknow.html
Topic archived. No new replies allowed.