-
February 19th, 2022, 03:01 PM
#1
Static Linking A -> B -> Program, Program must also be linked against A???
Hello!
I thought I knew how static linking works, but I guess I do not...
I made 2 (A and B) libraries in my project and a final program.
A and B are both static libraries.
B links A and the final program links B.
But when I run the program, I'm getting undefined reference from the linker about a symbol defined in A and used by B. If I link in the final program both A,B then I'm not getting any linking errors.
I made a minimal representation of this problem where you can find on GitHub:
https://github.com/babaliaris/static_linking_example
I though, since B links A, then the symbols would be defined in B as well so the final program would link against B without then need to link A as well, since B already has the binary code from A.
This is what I'm getting:
Code:
$ make
==== Building LibraryA (debug) ====
==== Building LibraryB (debug) ====
==== Building Programm (debug) ====
Linking Programm
/usr/bin/ld: bin/Debug/libLibraryB.a(libraryB.o): in function `libraryB_Print()':
libraryB.cpp:(.text+0x30): undefined reference to `libraryA_Add(int, int)'
collect2: error: ld returned 1 exit status
make[1]: *** [Programm.make:54: Programm] Error 1
make: *** [Makefile:38: Programm] Error 2
Thanks!
Last edited by babaliaris; February 19th, 2022 at 03:07 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|