Linux - SoftwareThis 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.
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.
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.
-- 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.
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.
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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.