Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-17-2014, 11:03 AM
|
#1
|
LQ Newbie
Registered: Apr 2014
Posts: 4
Rep:
|
Compiling dependencies
I am writing a static library (say called AAA) which has a dependency on another proprietary library (say called BBB)
I build AAA and link to BBB:
# gcc -c -o AAA.o AAA.c -l BBB
# ar rcs AAA.a AAA.o
AAA.a is produced and there are no errors
When I build a program which needs to use AAA, I compile it and link to AAA.
# gcc -Wall -g -c demo.c -o demo.o
# gcc -g -o demo demo.o -L. -l AAA
However I get a number of errors complaining about :
In function `SomeAAAfunctionname':
undefined reference to `somefunctionBBBname'
What am I missing?
What is the correct way to build a .c program which has a dependency on a library, when that library also has a dependency on another library.
Thanks
|
|
|
04-17-2014, 12:39 PM
|
#2
|
LQ Newbie
Registered: Apr 2014
Posts: 4
Original Poster
Rep:
|
OK I have just come across this link, which, if I understand it correctly says that it is not possible to link one static library to another.
http://stackoverflow.com/questions/2...atic-libraries
That is a huge oversight and makes producing layered, encapsulated components impossible using static libraries.
Come back Windows all is forgiven.
|
|
|
04-17-2014, 12:53 PM
|
#3
|
LQ Newbie
Registered: Apr 2014
Posts: 4
Original Poster
Rep:
|
...
|
|
|
04-17-2014, 11:36 PM
|
#4
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,647
|
if you do not actually post the code and the REAL errors
Then there is not much anyone can do to help
|
|
|
04-18-2014, 01:20 AM
|
#5
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,258
|
in general you do not need to link libraries to each other but to the application.
from the other hand:
Code:
# gcc -c -o AAA.o AAA.c -l BBB
you want to compile AAA.c and here you may use -I to specify include dirs but -l BBB will be ignored (gcc -c means there will be no linking at all).
|
|
|
04-18-2014, 05:25 PM
|
#6
|
LQ Newbie
Registered: Apr 2014
Posts: 4
Original Poster
Rep:
|
Real output follows :
-- building AAA library which depends on library BBB
root@mtu:~/bcm2835-1.36/examples/blink# gcc -c -o AAA.o AAA.c -l BBB
root@mtu:~/bcm2835-1.36/examples/blink# ar rcs libAAA.a AAA.o
-- building program which depends on library AAA (shows undefined references to entrypoints in BBB)
root@mtu:~/bcm2835-1.36/examples/blink# gcc -Wall -g -c demo.c -o demo.o
root@mtu:~/bcm2835-1.36/examples/blink# gcc -g -o demo demo.o -L. -l AAA
./libAAA.a( AAA.o): In function `initGPIO':
AAA.c: (.text+0x1a4): undefined reference to `BBB_init'
./libAAA.a( AAA.o): In function `delayms':
AAA.c: (.text+0x1d8): undefined reference to `BBB_delay'
Note that I do not want to have to relink the dependencies of a library I am using whenever I am building code which depends on that library. It it possible to do this - i.e. is it possible to build AAA so that the demo.c does not need to know about BBB.
Thanks
|
|
|
04-18-2014, 05:27 PM
|
#7
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by Hughey
OK I have just come across this link, which, if I understand it correctly says that it is not possible to link one static library to another.
http://stackoverflow.com/questions/2...atic-libraries
That is a huge oversight and makes producing layered, encapsulated components impossible using static libraries.
Come back Windows all is forgiven.
|
If you read your link, it is also not possible on Windows.
What you are talking about is combining object files into a new library. That is a librarian function, not a linking function.
Also note: You really need to be careful when you do this - make sure the licensing for all libraries are compatible. Otherwise your resulting library will not be distributable.
Now if this is strictly for local operation, the trivial way is to use the librarian to just add new modules to an existing library.
It doesn't matter if there are extra modules there - when an executable is created the unused modules are left out.
|
|
|
04-19-2014, 05:12 AM
|
#8
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,258
|
once more:
gcc -c means compiling, linking will not occure (using -c). Therefore executing this command: gcc -c -o AAA.o AAA.c -l BBB means only compiling, -l BBB will be ignored, it will not be used at all. It is not possible to link static (or dynamic) library that way.
Furthermore using that kind of syntax will not define any kind of dependency. ar rcs libAAA.a AAA.o will produce libAAA.a, but this lib will not contain any information related to BBB.
If you want to have a static library containing both AAA and BBB you need to do it by yourself. you need combine the content of both: copy libBBB.a to libCCC.a and ar r libCCC.a AAA.o for example will do the job. Afterward you need to link to CCC (or use both AAA and BBB)
|
|
|
04-19-2014, 09:06 AM
|
#9
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,970
|
Makefiles usually handle this. See man make. And automake.
|
|
|
All times are GMT -5. The time now is 03:01 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|