Fatal error C1020: Unexpected # endif

Source: Internet
Author: User

After learning openCV, I tried to run the online routine on the local machine and encountered various problems, so I recorded them for reference.

For VS2008, multiple projects can be created in one solution, but the unpleasant thing is that --

1. Processing of wide bytes

Modify project properties-> Configure properties-> in general, the "Character Set" option defaults to "use UNICODE Character Set", and each project must be manually changed to "use multi-Byte Character Set"

2. Additional linker dependencies (external Library)

You need to manually add cv200d. lib highgui200d. lib cxcore200d. lib to manually set properties for each project-> connector-> Add dependencies "Debug" and "Release ".

Note: The file name of the library to be added must be consistent with that of the openCV library generated by the local compiler. If openCV has been updated to version 3.15, the library generated after Cmake compilation may be cv315d. lib, depending on the local situation.

The dependency configuration ensures that the debug version and binary code of opencv are automatically re-compiled when the source code is changed.

 

For the "fatal error C1020: Unexpected # endif" error, the cause is roughly as follows:

 

If the Pre-compiled header is used, VC will search
# Include "stdafx. h"
Before this line of code is found, VC ignores all the code.

That is to say, in the following example, VC finds the second line # include "stdafx. h ", the first line # ifndef _ EiC is ignored, so" unexpected # endif "cannot be found.

# Ifndef _ EiC

# Include "stdafx. h"
# Include "cv. h"
# Include "cxcore. h"
# Include "highgui. h"
# Endif

 

Modify the preceding example as follows.

# Include "stdafx. h"

# Ifndef _ EiC

# Include "cv. h"
# Include "cxcore. h"
# Include "highgui. h"
# Endif

 

PS.: # ifndef V. S. # ifdef

 

# Ifndef avoid repeated compilation of multiple identical header files during compilation and avoid conflicts.

 

PPS .:

The first statement of all CPP implementation files is: # include "stdafx. h"

Because the compiler believes that,All the code before the command # include "stdafx. h" is pre-compiled.It skips the # include "stdafx. h" command and uses projectname. pch to compile all the code after this command.

 

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.