Partially Linked to Dynamic Linking in C
up vote
2
down vote
favorite
I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:
/* main2.c */
#include <stdio.h>
#include "vector.h"
int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];
int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}
and libvector.so just a DLL that provides definition needed by main2.c
So my questions are:
Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?
c linker dynamic-linking
add a comment |
up vote
2
down vote
favorite
I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:
/* main2.c */
#include <stdio.h>
#include "vector.h"
int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];
int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}
and libvector.so just a DLL that provides definition needed by main2.c
So my questions are:
Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?
c linker dynamic-linking
1
The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would callp2
and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
– Jonathan Leffler
Nov 8 at 6:49
There is only one object file in the partially linked executable itself (main.o
)
– Antti Haapala
Nov 8 at 7:02
@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:
/* main2.c */
#include <stdio.h>
#include "vector.h"
int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];
int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}
and libvector.so just a DLL that provides definition needed by main2.c
So my questions are:
Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?
c linker dynamic-linking
I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:
/* main2.c */
#include <stdio.h>
#include "vector.h"
int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];
int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}
and libvector.so just a DLL that provides definition needed by main2.c
So my questions are:
Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?
c linker dynamic-linking
c linker dynamic-linking
edited Nov 8 at 7:26
Antti Haapala
79k16148191
79k16148191
asked Nov 8 at 6:37
amjad
3047
3047
1
The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would callp2
and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
– Jonathan Leffler
Nov 8 at 6:49
There is only one object file in the partially linked executable itself (main.o
)
– Antti Haapala
Nov 8 at 7:02
@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20
add a comment |
1
The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would callp2
and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
– Jonathan Leffler
Nov 8 at 6:49
There is only one object file in the partially linked executable itself (main.o
)
– Antti Haapala
Nov 8 at 7:02
@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20
1
1
The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call
p2
and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.– Jonathan Leffler
Nov 8 at 6:49
The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call
p2
and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.– Jonathan Leffler
Nov 8 at 6:49
There is only one object file in the partially linked executable itself (
main.o
)– Antti Haapala
Nov 8 at 7:02
There is only one object file in the partially linked executable itself (
main.o
)– Antti Haapala
Nov 8 at 7:02
@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20
@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The partially linked executable would have all of the .o
object files (here only main.o
) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The partially linked executable would have all of the .o
object files (here only main.o
) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.
add a comment |
up vote
1
down vote
The partially linked executable would have all of the .o
object files (here only main.o
) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.
add a comment |
up vote
1
down vote
up vote
1
down vote
The partially linked executable would have all of the .o
object files (here only main.o
) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.
The partially linked executable would have all of the .o
object files (here only main.o
) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.
answered Nov 8 at 7:07
Antti Haapala
79k16148191
79k16148191
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53202594%2fpartially-linked-to-dynamic-linking-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call
p2
and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.– Jonathan Leffler
Nov 8 at 6:49
There is only one object file in the partially linked executable itself (
main.o
)– Antti Haapala
Nov 8 at 7:02
@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20