LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2013, 06:54 AM   #1
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Rep: Reputation: Disabled
Question creating .SO (shared object) file in C code in linux


Quote:
Dear sir,

i have one confusion related to creating the .so file
i am posting the Makefile which creates the .so
It is all ready written but i have some confusions about it.
Code:
all:
        g++ -fPIC -o lib/libcyusb.o -c lib/libcyusb.c
        g++ -shared -Wl,-soname,libcyusb.so -o lib/libcyusb.so.1 lib/libcyusb.o -l usb-1.0 -l rt
        cd lib; ln -sf libcyusb.so.1 libcyusb.so
        rm -f lib/libcyusb.o
clean:
        rm -f lib/libcyusb.so lib/libcyusb.so.1
help:
        @echo   'make           would compile and create the library and create a link'
        @echo   'make clean     would remove the library and the soft link to the library (soname)'
~                                                                                                                                            
~                                                                                                                                            
~
Quote:
my confusions are,
1. Why there is two .so files created "libcyusb.so" "libcyusb.so.1"
what is use of it, what this libcyusb.so.1. is doing
2. what does this command do
Code:
cd lib; ln -sf libcyusb.so.1 libcyusb.so
Quote:
Please help me to understand these things
this file is from the open source utility cyusb for cypress

i want to learn and create my .so also so want to know these things

Thanks & Regards
Rohaan

Last edited by rohaanembedded; 05-31-2013 at 07:19 AM.
 
Old 05-31-2013, 08:16 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Recommend you perform an "ls -l" on those two files. I believe you will see that the straight .so file is a symbolic link pointing to the .so.1 file and the so.1 file is the true shared object binary.

This is typical for how .so files are set up, and my assumption has always been that if you have <blah-blah>.so, then you'll always want to have the file in that name. But you can try or cause an upgrade by changing the target of the symbolic link. And then further, the extension on the original binary shared object library file can give you the version, such as .so.1.2.12 means version "1.2.12" if the coder intended it to be that way.

Here's what I'm talking about

Code:
lrwxrwxrwx 1 root root    11 2011-01-11 14:56 libacl.so -> libacl.so.1
lrwxrwxrwx 1 root root    15 2010-11-29 15:06 libacl.so.1 -> libacl.so.1.1.0
-rw-r--r-- 1 root root 30312 2010-02-08 06:09 libacl.so.1.1.0
libacl.so.1.1.0 is the compiled/linked library.
libacl.so.1 is a symbolic link to it
libacl.so is another symbolic link to it.

I don't know why there are two symbolic links, or the true history or why this is done, however this is the first level of explanation for you. And perhaps another responder will explain some more about the full reasons for this.
 
3 members found this post helpful.
Old 05-31-2013, 08:39 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
This method is commonly used to allow applications built against the library to be completely general about the version in use, or to be a s specific as necessary about the library version required. Symbolic links with progressively more specific versioning suffixes allow the library user to craft Makefiles that can accommodate this. Presumably, the '.1' suffix represents the current version of the library package. Subsequent revisions will alter that suffix to reflect the modifications.

--- rod.
 
2 members found this post helpful.
Old 05-31-2013, 10:40 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
The basic idea:

libFoo has two-level version number: major and minor, changing 'minor' means compatible change,
changing 'major' means incompatible change.
The libraries know their 'major' number (cf DT_SONAME), and executables know the 'major' number of the used libraries (cf DT_NEEDED).

Example:

major=3, minor=4.5
Code:
libFoo.so->libFoo.so.3.4.5 -- linker uses this
libFoo.so.3->libFoo.so.3.4.5 -- linked executables use this
libFoo.so.3.4.5 -- this is the actual shared lib
So, what happens when you install version 3.5.7 (major=3, minor=5.7)?
Well, this is a compatible change, the symlinks are updated, so the old programs will use the new shared lib.
Code:
libFoo.so->libFoo.so.3.5.7 -- linker uses this
libFoo.so.3->libFoo.so.3.5.7 -- linked executables use this
libFoo.so.3.5.7 -- this is the new shared lib
And then, you install version 4.1 (major=4, minor=1).
This is a incompatible change, the old programs will still use the old shared lib, only the newly linked programs will use the new lib.

Code:
libFoo.so.3->libFoo.so.3.5.7 -- previously linked executables use this
libFoo.so.3.5.7 -- this is the old shared lib
libFoo.so->libFoo.so.4.1 -- linker uses this
libFoo.so.4->libFoo.so.4.1 -- newly linked executables use this
libFoo.so.4.1 -- this is the new shared lib
Note: Using libtool might be useful, if you follow some good tutorial, because it is not exactly intuitive for beginners.
http://www.gnu.org/software/libtool/...#Using-libtool

Last edited by NevemTeve; 05-31-2013 at 10:42 AM.
 
3 members found this post helpful.
Old 06-02-2013, 07:29 AM   #5
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Smile

Thanks everybody,


I am trying to learn the things...

thanks for support!!!

Thanks & Regards
Rohan
 
Old 06-03-2013, 12:13 AM   #6
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Original Poster
Rep: Reputation: Disabled
Question

Quote:
Dear everyone,


i have used the "libcyusb.so" to develope my code and now i have created my own .os using

in my makefile
Code:
g++ -c -fPIC        Usb.c -o Usb   -L ../../lib -l cyusb  
        g++ Usb.o -shared -o libUsb.so
Quote:
so can it be possible if use my .so and header file to develop the another application over it??? will it be possble to use my header and .so only or i have to use "libcyusb.so" also???

it is it necessary to have the .so.1 or can i use my .so only???

Thanks & Regards
Rohan
 
Old 06-03-2013, 05:39 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
If you're programming for your own purposes and don't intend to release this and have subsequent revisions, then do what you wish; however if you're developing for a customer or for other person's use then please follow the conventions. Many is the time that I felt I was doing a brief, one-time program and would never send out any revisions ... many is the time I've ended up doing not only a revision, but several and instead a much larger project.
 
2 members found this post helpful.
Old 06-03-2013, 05:50 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 6 .

http://tldp.org/HOWTO/Program-Librar...libraries.html
>> 3.4. Creating a Shared Library

Example :
libUsb.so.1.0.0 is the "Real name"
libUsb.so.1 is the "so name". Used for run time.
libUsb.so is a link to the version, you want to use for compiling.

I.e. when you update to / create a later version of libUsb,
say libUsb.so.2.0.0, you can decide to compile with this new version,
by changing libUsb.so to point to libUsb.so.2.0.0 .
And : You can have two run time versions, libUsb.so.1 and libUsb.so.2 .

-

Last edited by knudfl; 06-03-2013 at 05:55 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] error while loading shared libraries: libacl.so.1: cannot open shared object file: fl0 Slackware 4 03-22-2013 03:32 AM
error while loading shared libraries: libcrypt.so.1: cannot open shared object file: xmixail Linux - Kernel 15 07-29-2012 08:39 PM
creating a shared object vin_pll Linux - General 1 12-18-2008 12:43 PM
error while loading shared libraries: libstdc++.so.5: cannot open shared object file PaulyWally Debian 2 10-18-2008 05:59 PM
error while loading shared libraries: libgvc.so.3: cannot open shared object file coolrock Slackware 6 01-17-2007 05:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration