Notes for C & C ++ multi-system integration

Source: Internet
Author: User

C & C ++ systems often encounter multi-system inheritance, such as introducing a third-party library to an existing system or integrating several existing databases. Sometimes, we found that compilation and linking may cause some inexplicable and wonderful problems. The following describes the problems encountered:

1. Compilation Error

(1) the header file is not found.

This solution is relatively simple. First, determine whether the system does not reference the header file, and then determine whether the compiler can find the path of the header file.

(2) The type, variable, or function is not declared.

There are two scenarios:

A. There are multiple header files with the same name. As a result, the compiler does not actually need the header files.

Solution: Put the required header file path on the front.

B. The correct header file is referenced, and it is clearly declared or defined, or not found

The problem is probably due to Conditional compilation. Some macros defined in the compilation environment block the real definition. You can use # error "MSG" to test whether the compiler does not process the definition. Just open the macro.

2. Link error

Compilation errors are generally because the symbols are not found. There are two main types of errors:

(1). No symbols are defined.

There is no other way to add this.

(2). If you have defined a symbol and the link cannot be found, there are three situations:

A. Conditional compilation blocks function definitions

Check whether the compiler has compiled the required interface.

B. similar commands of nm can be used to check whether there is a symbolic definition. In this case, the most likely reason is. if the file name is duplicated, you can check the source file name of the symbol and modify it to the unique name.

C. when C ++ calls C functions, it will be considered to require name conversion by default. For example, the revert interface, C ++ will call interfaces similar to _ zxyrevert_sjx3, however, after the C source code is compiled, the generated symbol is _ revert.

You need to declare the C interface referenced in C ++ with extern "C", which is also the role of extern "C.

 

In summary, you must note that,C ++ references the C interface,Duplicate header file name,Source file name duplication, It will often lead to inexplicable problems, you need to pay attention!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.