Answer the question
In order to leave comments, you need to log in
Compiling c++?
Hello everyone, explain one thing about compiling sources, there is a code as an example:
#mainx.cpp#
#include <iostream>
#include "printx.h"
using namespace std;
int main()
{
int a = 4;
cout << "Calling function!" << endl;
cout << printx(a) << endl;
return 0;
}
void printx(int );
#include <iostream>
#include "printx.h"
void printx(int x)
{
for (int i = 0; i < x; i++) {
std::cout << "hello" << std::endl;
}
}
Answer the question
In order to leave comments, you need to log in
it turns out that mainx learns about the fact that there is a function printx () at the stage of linking [mainx.o] and [printx.o]?
objdump -dr mainx.o
...
0000000000000000 <main>:
0: 55 push %rbp
...
3a: 89 c7 mov %eax,%edi
3c: e8 00 00 00 00 callq 41 <main+0x41>
3d: R_X86_64_PLT32 _Z6printxi-0x4
41: b8 00 00 00 00 mov $0x0,%eax
46: c9 leaveq
47: c3 retq
...
readelf -a mainx.o
...
Relocation section '.rela.text' at offset 0x580 contains 12 entries:
Offset Info Type Sym. Value Sym. Name + Addend
...
00000000003d 001400000004 R_X86_64_PLT32 0000000000000000 _Z6printxi - 4
...
Symbol table '.symtab' contains 25 entries:
Num: Value Size Type Bind Vis Ndx Name
...
20: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _Z6printxi
...
readelf -a printx.cpp
...
Symbol table '.symtab' contains 24 entries:
Num: Value Size Type Bind Vis Ndx Name
...
14: 0000000000000000 75 FUNC GLOBAL DEFAULT 1 _Z6printxi
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question