Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

C/C++ shared libraries on Linux.

Programming


Tags
dinamyc shared library, ldd

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago   -   Original Discussion by jose_spain
jose_spain's Unix or Linux Image
jose_spain jose_spain is offline
Registered User
 
Join Date: Apr 2018
Last Activity: 21 April 2018, 10:16 AM EDT
Posts: 4
Thanks: 0
Thanked 2 Times in 2 Posts
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:


Code:
#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:


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

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


hello.c:


Code:
#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:



Code:
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:



Code:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./

./hello

It works right.


4) My question:

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


Code:
    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?
Moderator's Comments:
C/C++ shared libraries on Linux. Please use CODE tags when displaying sample input, output, and code segments.

Last edited by Don Cragun; 1 Week Ago at 06:23 PM.. Reason: Add missing CODE and ICODE tags.
The Following User Says Thank You to jose_spain For This Useful Post:
dodona (1 Week Ago)
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago   -   Original Discussion by jose_spain
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 26 April 2018, 3:59 PM EDT
Location: NM
Posts: 11,360
Thanks: 605
Thanked 1,153 Times in 1,062 Posts
libhello.so has to be in the LD_LIBIRARY_PATH variable for ldd to find it. You should NOT put personal directories in the path.
The Following User Says Thank You to jim mcnamara For This Useful Post:
dodona (1 Week Ago)
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago   -   Original Discussion by jose_spain
dodona's Unix or Linux Image
dodona dodona is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 25 April 2018, 8:12 AM EDT
Posts: 34
Thanks: 87
Thanked 5 Times in 4 Posts
Quote:
Originally Posted by jim mcnamara View Post
libhello.so has to be in the LD_LIBIRARY_PATH variable for ldd to find it. You should NOT put personal directories in the path.
for testing purposes, why not! Jose only want's to see that it works principally.
    #4  
Old Unix and Linux 1 Week Ago   -   Original Discussion by jose_spain
jose_spain's Unix or Linux Image
jose_spain jose_spain is offline
Registered User
 
Join Date: Apr 2018
Last Activity: 21 April 2018, 10:16 AM EDT
Posts: 4
Thanks: 0
Thanked 2 Times in 2 Posts
Thanks,

I have excuted:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:[FULL PATH TO .so FILE]

where:
[FULL_PATH_TO .so FILE] = /home/jose/.../hello_program

But if I execute the command: ldd hello
the output follows being:

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 am working on Ubuntu 14.0.4
The Following User Says Thank You to jose_spain For This Useful Post:
dodona (1 Week Ago)
Sponsored Links
    #5  
Old Unix and Linux 1 Week Ago   -   Original Discussion by jose_spain
dodona's Unix or Linux Image
dodona dodona is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 25 April 2018, 8:12 AM EDT
Posts: 34
Thanks: 87
Thanked 5 Times in 4 Posts
Quote:
Originally Posted by jose_spain View Post
Thanks,
I have excuted:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:[FULL PATH TO .so FILE]
where:
[FULL_PATH_TO .so FILE] = /home/jose/.../hello_program
...
LD_LIBRARY_PATH needs the path and not the file name.
check out: LD_LIBRARY_PATH=${LD_LIBRARY_PATH}: /home/jose/.../
Sponsored Links
    #6  
Old Unix and Linux 4 Days Ago   -   Original Discussion by jose_spain
dryden's Unix or Linux Image
dryden dryden is offline
Registered User
 
Join Date: Apr 2018
Last Activity: 24 April 2018, 2:25 AM EDT
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
There are also programs like patchelf that can set the "rpath" after linking.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Naming conventions for shared libraries in Linux neked UNIX for Advanced & Expert Users 2 11-20-2008 10:36 AM
how to view loaded shared libraries by running processes in linux princelinux Programming 3 01-17-2007 06:44 AM
Shared Libraries wojtyla Linux 1 09-16-2005 12:14 AM
shared libraries thalex Programming 2 11-29-2001 08:32 AM
Shared libraries Micky Programming 0 11-12-2001 03:25 AM



All times are GMT -4. The time now is 08:53 PM.