Strange compilation problems (linux)

Source: Internet
Author: User
The strange compilation problem (linux)-General Linux technology-Linux technology and application information. The following is a detailed description. This problem is often encountered:
When a. h contains B. h
B. h and a. h are inexplicable errors, even though they have been used.
# Ifndef XXXXXXXXXXXXXXXX
# Define XXXXXXXXXXXXXXXX
# Denif
And so on to prevent repeated compilation of macros.

Later I heard that I could use a pre-statement to solve this problem.
Direct class a in B. h;
OK. The compilation is okay, but a "segment error" occurs when you run it"
Clean up the project, compile a new compilation, and then run smoothly.
I still don't know why, so I should record it first to save the mysterious "segment error" and when to jump out again.

The other is that, in linux (eclipse-cdt), when C code and C ++ are mixed together, the mysterious compilation error comes again.
There is no circular include this time.
Divide the C code into a. h and a. c files. Suppose there is a function ().
The Link tells you that the undefine function () is not defined (). Isn't it silly to call the compiler? It is implemented in a. c.
A. h is also included in A.C. I cannot afford to hide it. Directly move all of a. c to a. h. It seems much more honest.

B. h, c. h also contains. h (or the C ++ template header file), the problem arises again. This is multi define)
However, I have added "# ifndef .... # Define ..... # Endif "statement.
In the past, we saw that "extern C" was added to the Embedded C code in c ++. After a try, the problem persists.
You may not be able to do it yourself.
Adding a namespace ASpace does not work. I don't know how it was done. Later I wrote it in a namespace named a.h.
# Ifndef _ A_H _
# Define _ A_H _
Namespace
{
Void function ()
{

}
}
# Denif
The error disappears. The conclusion is that C ++ uses less C style and more classes. This saves a lot of trouble.

The error is strange, but it is still not deep enough. I know little about this.

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.