Notes for linux Dynamic Link-general Linux technology-Linux programming and kernel information. Read the following for details. In the past two days, I have practiced how to create dynamic links in linux. I feel that although the information on the Internet is informative, there are still omissions.
1. Differences between g ++ and gcc
In some cases, you can change the value of cc.
2. the type check in gcc4.1.1 seems to be strict. The void * type returned by dlsym cannot be converted to the corresponding function pointer type, and must be forcibly converted. Some online examples cannot be edited here.
3. During explicit calling, you must pay attention to the declaration of the dynamic library function. You may need to add extern "C" to execute the function normally. (Explicit calls are loaded at runtime, so compilation is successful, but execution is incorrect .) You can run the nm command to check the symbol table of the Linked database to locate the problem.
Differences between gcc and g ++
Both gcc and g ++ are GNU compilers.
Misunderstanding 1: gcc can only compile c code, while g ++ can only compile c ++ code
Both can be used, but note the following:
1. suffix. c, gcc treats it as a C program, while g ++ treats it as a c ++ program; suffix. cpp, both of which are considered as c ++ programs. Note that although c ++ is a superset of c, their syntax requirements are different. C ++ syntax rules are more rigorous.
2. in the compilation phase, g ++ calls gcc. For c ++ code, the two are equivalent, but because the gcc command cannot be automatically connected to the library used by the C ++ program, therefore, we usually use g ++ to complete the link. For the sake of unification, we simply use g ++ to compile/link all. This gives us the illusion that, it seems that cpp programs can only use g ++.
Misunderstanding 2: gcc does not define the _ cplusplus macro, while g ++ will
In fact, this macro only indicates that the compiler will interpret the code in the C or C ++ syntax. As mentioned above, if the suffix is. c. If the gcc compiler is used, the macro is undefined. Otherwise, the macro is defined.
Misunderstanding 3: only gcc can be used for compilation, and only g ++ can be used for Link
Strictly speaking, this sentence is not a mistake, but it obfuscated the concept. It should be said that gcc/g ++ can be used for compilation, the link can use g ++ or gcc-lstdc ++. Because the gcc command cannot be automatically connected to the library used by the C ++ program, g ++ is usually used to complete the connection. However, in the compilation phase, g ++ automatically calls gcc, which is equivalent to the two.
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service