Something I still haven't quite absorbed. Nearly all of my development has involved generating and compiling my code together statically, without the use of linking dynamic libraries (dll or .so).
I understand in this case how the compiler and linker can resolve the symbols as it is stepping through the code.
However, when linking in a dynamic library for example, and the dynamic library has been compiled with a different compiler than the main code, will the symbol names not be different?
For example, I define a structure called RequiredData in my main code as shown below. Imagine that the FuncFromDynamicLib() function is part of a separate dynamic library and it takes this same structure RequiredData as an argument. It means that somewhere in the dynamic library, this structure must be defined again? How can this be resolved at the time of dynamic linking that these structures are the same. What if the data members are different? Thanks in advance.
#include <iostream>
using namespace std;
struct RequiredData
{
string name;
int value1;
int value2;
};
int FuncFromDynamicLib(RequiredData);
int main()
{
RequiredData data;
data.name = "test";
data.value1 = 120;
data.value2 = 200;
FuncFromDynamicLib(data);
return 0;
}
//------------Imagine that this func is Part of dynamic library in another file--------------------
int FuncFromDynamicLib(RequiredData rd)
{
cout<<rd.name<<endl;
cout<<rd.value1<<endl;
cout<<rd.value2<<endl;
}
//------------------------------------------------------