To compile a dynamic library, you must add the "-shared" option. When compiling the dynamic library d1.so, if the content of the dynamic library d2.so is used, you only need to add the header file directory (-I) of d2.so, without specific implementation.CodeThis basically achieves the independence of D1 and D2.
When compiling the executable body, all libraries (-L and-l) must be added, and the related header file directory (-I) must also be added, in addition, the "-LDL" parameter must be added.
If there is a dependency between libraries, you must add the "-rdynamic" parameter. This parameter adds all the symbols to the dynamic symbol table, in this way, the contained library symbols can be used.
Polymorphism is used for dynamic libraries opened by dlopen. The implementation mechanism of this method is different after GCC (G ++) 3.0, so the dynamic_cast type conversion may be problematic. Add the "-wl,-e" option when compiling the execution body,Note: commaAnd add rtld_global to the dlopen parameter. In this way, the symbol in the execution body is changed to a global symbol, and the dynamic library opened by dlopen can also use the symbol in the execution body.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.