About the -ldl flag while compiling and linking C++ files

左心房为你撑大大i 提交于 2019-12-03 14:43:18
n. 'pronouns' m.

-ldl is a library designation for the linker. It tells the linker to find and link a file named libdl.so (or sometimes libdl.a). It has the same effect as placing a full path to the library in question in the same position of the command line.

Library and object order on the command line does matter. Normally if library A calls library B, B should be placed after A on the command line. All libraries should normally go after all object files. This is covered extensively in several SO questions and answers like this one.

As for the second question, no, an address of a function doesn't change at run time unless you dlopen a shared library, then unload it, then dlopen it again. In your case, since you don't dlopen the library, it is safe to keep the function address in a static variable. Of course if you run multiple threads you need to ensure thread safety somehow (mutex it out, or use thread-local storage).

Begin with your second question, dynamic linking works during run time either way in C/C++ we call later binding with this -> operation. Of course when you are invoking later binding declared like an interface or class instance, should be pointing to the specified object and memory location for that object.

The first one question is more i think specific to compiler. I guess you are compiling not in Visual Studio(Not in Windows OS) if i am right u should ask to the vendor of the compiler to configure debugging properties. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!