VS programming common compilation and Link errors, vs programming Compilation
Common error 1:
Error 2 error LNK1120: 1 unresolved externals
Error 1 error LNK2019: unresolved external symbol _ imp _ PathFileExistsA @ 4 referenced in function "public: void _ thiscall myspace: RCSetupWithVirtual: StartupSetup (class std :: basic_string <char, struct std: char_traits <char>, class std: allocator <char> )"(? StartupSetup @ RCSetupWithVirtual @ myspace @ QAEXV? $ Basic_string @ DU? $ Char_traits @ D @ std @ V? $ Allocator @ D @ 2 @ std @ Z)
First, note that this is a link error. This error occurs when I use the PathFileExists system API. Such errors are common, meaning that the external symbol cannot be identified. Why? This is because the corresponding lib file is not included. For beginners, it may be unfamiliar with lib files and dll files. In fact, it is very simple. Why can we use the cout and cin functions when writing a head file containing # include <iostream>? It is because our computer has the implementation code of these functions, but we can see that their header files are compiled into lib files (static links) or dll (Dynamic Links ). Of course we can't see the content in it (both binary ). The solution to this problem is very simple. First, go to MSDN to search for the API you are using, for example, PathFileExists, which contains details about using this API:
Header file to be included, lib file. All we need to do is include this lib file. Project properties --- Linker --- Input --- Additional Dependencies click the drop-down button to select Edit and put it directly.
Continue the compilation and try again.
Common Error 2:
Error 2 error LNK1120: 1 unresolved externals
Error 1 error LNK2019: unresolved external symbol _ WinMain @ 16 referenced in function ___ tmainCRTStartup
Or
Error 2 error LNK1120: 1 unresolved externals
Error 1 error LNK2019: unresolved external symbol _ main referenced in function ___ tmainCRTStartup
These are two very common mistakes for beginners, even other programmers, sometimes writing them like this. The error indicates that the console project was created when you created the project. As a result, the main function is written as WinMain; or the win32 project is created, and the main function is written as main. Some people re-create a project, which is of course not good. Any settings of VS can be changed. Try to understand these things. The modification is: Project properties --- Linker --- System --- SubSystem. Note that the best practice is Not Set. Why? This is explained in "Windows core programming". After this setting, the system will automatically match the main function. You can write any project. This is the perfect solution!
Common error 3:
Error 1 error C2664: 'bool PathFileExistsW (LPCWSTR) ': cannot convert argument 1 from 'const char *' to 'lpcwstr'
The reason is that I used this statement, PathFileExists (fileName. c_str ())
The parameter type of PathFileExists is LPCTSTR, and fileName is string. This shows how to convert string to the LPCTSTR type. In fact, you only need to use the. c_str () type. This function is not only valid for char *, but will be judged. If it is wchar_t *, it will be converted accordingly. This error is caused by the Character Set setting problem. It is very simple. In this case, you can directly Set the project attribute --- General --- Character Set to Not Set. Use the wildcard type in a unified manner to ensure compatibility.
**************************************** **************************************** ************
Error 1:
Error 1 error C2664: 'int _ PTR DialogBoxParamA (HINSTANCE, LPCSTR, HWND, DLGPROC, LPARAM) ': cannot convert argument 4 from 'bool (_ stdcall *) (HWND, UINT, WPARAM, LPARAM) 'to 'dlgproc' e: \ virtualdesktop. cpp171 VirtualDesktop
2 intelliisense: argument of type "bool (_ stdcall *) (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)" is incompatible with parameter of type "DLGPROC" e: \ VirtualDesktop. cpp175 VirtualDesktop
How can this error be reported? I wrote a simple program as follows:
bool WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ return false;}int APIENTRY WinMain(HINSTANCE hInstexe, HINSTANCE, PSTR nCmdLine, int nCmdShow){ DialogBox(hInstexe, MAKEINTRESOURCE(IDD_DIALOG1), NULL, Dlg_Proc); return 0;}
It only starts a dialog box, but it prompts a problem with the Dlg_Proc function. Later I compared a correct code and found that it was originally the return value of the function bool. The correct return value is BOOL. Are these two differences? Of course it is different.
typedef int BOOL;
See it? The type is incorrect! The foundation is not solid, and you are not careful.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.