Several typical C + + errors

Source: Internet
Author: User

1, Error: Debugger: An unhandled Status_dll_not_found exception program was raised during process load "[3048] Text2.exe: Native" exited with a return value of -1073741515 (0xc0000135). Workaround: You can not find the dynamic library used in your program, put the DLL file in the same directory as EXE file.

2, BUG: Error C2011: "Calarm": "Class" type redefined "Go" in the file header with "#pragma once", "#pragma once" is a more commonly used instructions, By adding this instruction at the beginning of the header file, you can ensure that the header file is compiled once, #pragma once is used to prevent a file from being included multiple times, #ifndef, #define, #endif用来防止某个宏被多次定义. It has the same effect as #ifndef __test_h__ #define__TEST_H__ code #endif. Error 1 LNK1104: Unable to open file "\lib\qttestd4.lib" D:\getBaseInfo\getBaseInfo\LINK

3, Error:

Workaround: Place the *.dell file in the. exe directory.

4, in the form of folders directly using third-party source files, you need to put the source files in the project. Problem: You need to add a third-party control, the control itself a folder, but the folder has a lot of folders. Inside all is the *.js file, if manually a right-click Add folder, in the folder under the way to add folders to do, there may be dozens of to add, very troublesome, what good way to add together.

Method: Copy to a folder in the project directory.

Click Show All files in the Project Explorer Gadget bar.

These files appear, but are grayed out, indicating that they are not part of the project.

Click Folder, right-click and select Include in Project.

Select Always copy in the output of the Properties pane.

5, not only to the directory,. Lib and other configuration to the path of VS, if necessary, in the program to include the specific header files.

6, sometimes reported: error LNK2019: unresolved external symbol _err_remove_state, the symbol in the function "Pu this kind of error plus the following two libraries can be:?????? D:\server\lib\libeay32.lib D:\server\lib\ssleay32.lib

7, sometimes error: Cannot find ordinal 459, cannot locate ordinal 459 in dynamic link library. This kind of error only need to put Libeay32.dll,ssleay32.dll to *.exe, that is, the project executable directory can be.???????

8, when the following error occurred: Error 2 C2146: syntax error: Missing ";"  (in front of the identifier "buffermutex_") d:\t Error 1: "Boost": Not a class or namespace name D:\TESTQT\TESTQT\TESTQT. Error C2039: "Scoped_lock": not a member of "Boost" D:\testQT\testQT\testqt.cpp 216 please check if all header files are included. Even if the property configuration is correct, you should also include the head file again, otherwise it will not be found.

9, Error  4 error LNK2005: "Public:virtual __thiscall boost::p roperty_tree::p tree_error::~ptree_error (void ) "([email  Protected] [email protected] @@[email protected] ) have been defined in Main.obj  d:\testqt\testqt\testqt.obj the reason for my program error is 2nd: "contains duplicates of header files". As prompted by the Property_tree problem, the checker found the following header file appears in Main.cpp:    #include <boost/property_tree/ptree.hpp>     #include <boost/property_tree/json_parser.hpp> and the above header file in the testqt.cpp of the project also appeared, will be main.cpp in the removal of it.

The

causes LNK2005 errors mainly in the following situations: 1. The global variables are defined repeatedly. There may be two situations: A, for some novice programmers, sometimes the definition can be used where global variables are needed. In fact, this is wrong, the global variable is for the entire project. The correct should be defined in a CPP file as follows: Int g_test, then in the CPP file used should use: extern int g_test, if you still use int g_test, then will produce LNK2005 error, General error error message similar to: aaa.obj error LNK2005 int book c? [email protected] @3ha already defined in Bbb.obj. Remember that you cannot assign a value to a variable or there will be a LNK2005 error. What is needed here is "declaration", not "definition"! According to the C + + standard, a variable is declared and must satisfy two conditions, otherwise it is defined as: (1) Declaration must use the extern keyword, (2) cannot assign an initial value to the variable so, the following is the declaration: extern int A; The following is the definition of int A; int a = 0; extern int a = 0; B, for programmers who are not so rigorous in programming, always define a global variable in a file that needs to use a variable, and do not take into account the variable name, which is often prone to duplicate variable names and cause LNK2005 errors.

2. The header file contains duplicates. Often need to include the header file contains variables, functions, class definitions, in other areas of use have to be included more than once, if the header file does not have the relevant macros and other measures to prevent repeated links, then there will be a LNK2005 error. The workaround is to do similar processing in the header file that needs to be included: #ifndef my_h_file//If this macro is not defined #define MY_H_FILE//define this macro ...//header file main content ... #endif above is done using macros, You can also use precompilation to do this by adding: #pragma once//header file Body 3 in the header file. caused by using a third-party library. This situation is mainly caused by the C run-time function library and the library Conflict of MFC. The way to do this is to put the wrong library in front of another library. This error can be caused by choosing a different C function library. Microsoft and C have two C run-time libraries, one is a common library of functions: LIBC.LIB, multithreading is not supported. Another type of support is Multithreading: MSVCRT.lib. If a project is mixed with these two libraries, it may cause this error, in general it requires MFC libraries to be linked before the C run-time library, so it is recommended to use msvcrt.lib that support multithreading. So before you use a third-party library, you first need to know what library it is linked to, or it may cause LNK2005 errors. If you have to use a third-party library, you can try to modify the method as described below, but there is no guarantee to solve the problem, the first two methods are provided by Microsoft: A, select the VC menu Project->settings->link->catagory Select Input , and then fill in the Edit column of ignore libraries you need to ignore the library, such as: Nafxcwd.lib; Libcmtd.lib. Then in the Object/library Modules edit column fill in the correct library order, here need you can determine what is the correct order, hehe, God bless you! B, select the VC menu Project->settings->link page, and then enter/verbose:lib in the Edit tab of project options so that you can see the link order in the Output window during the compilation of the linker. C, select the VC menu project->settings->c/c++ page, catagory Select code generation and then in the user Runtime Libraray Select the multithread DLL and other libraries, Try each of them individually. About compilationThe relevant processing process of the translator, refer to: http://www.donews.net/xzwenlan/archive/2004/12/23/211668.aspx

This is the LNK2005 I have encountered several cases of errors, there must be other circumstances may also cause this error, so I do not want you to read this article after the encounter LNK2005 error, do not think about the wrong to take a seat.   The process of programming is a process of thinking, so still more to start your mind, so the harvest will be more! Found from someone's blog: Solution One: Take the action function that the main function contains. cpp, and change to the header file. h, then you can resolve the error as above. Solution Two: Re-open the compiler, reopen the file, open the main function. cpp, then compile run, open FileView, which has a external dependencies, Head file. h, and the action function. CPP is added here so that the main function is compiled and run. CPP, the program runs successfully! I encountered should be the first case mentioned in Csdn, but I am using someone's blog solution to solve the problem, learning ...

10,testb.cpp (6): Error C2027: undefined type ' A ' was used
D:\dxsdk\extras\directshow\samples\c++\directshow\course_client2\destop capture Filter\testb.h (4): See Statement "a"
TestB.cpp (6): Error C2227: The left side of "->amethod" must point to class/struct/union

  

The procedure is as follows:

TestA.h:

#if!defined (_a_)
#define _a_
#include "TestB.h"
Class a{
Public
b b;
Public
Amethod ();
};
#endif

TestA.cpp:

#include "TestA.h"
A::amethod () {

}

TestB.h
#if!defined (_b_)
#define _b_
# include "TestA.h" <--This include does not make
Class A;
Class b{
Public
A * A;
Public
SetA (a*a);
Bmethod ();
};
#endif

TestB.cpp
#include "TestB.h"
B::seta (a*a) {
this->a=a;
}
B::bmethod () {
A->amethod ();
}

Workaround:

TestB.cpp
#include "TestB.h"
#include "TestA.h"

Reason:

There is only a pointer to Class A in class B, so it is possible to define Class B with a forward declaration of Class A.
But Class A uses Class B as a member, so when you define Class A, you see the full definition of Class B.

Several typical C + + errors

Related Article

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.