I have been developed with GCC. I haven't used VC. I have installed a large pile of plug-in when I write code. Visual Assist X, Wndtabs, Spelly, Project Line Counter, Sourcestyler C , is very cool, feel better than VI With more, but compiled, the nightmare began.
The syntax error is not much, and it will be changed soon.
Next, I met a mistake.
Error C2065: 'TryEntercriticalsection': undeclared identifier
Very strange, the other functions of the key segment do not have such a problem, only this function has, I have to help Google, find that I need to add a macro definition, _win32_winnt = 0x500, meaning is only from a version of Windows start support, it seems It is Win2000. It doesn't need to support it before, so you can support some new functions, I think this kindentercriticalsection should be one of them.
This problem has not been, and there is a new problem, and a lot of Error C2011 suddenly jumped.
Just like this error C2011: 'fd_set': 'Struct' Type Redefinition, and also prompts to define conflicts in Winsock.h and Winsock2.h. Macro Redefinition.
I started thinking that this problem is repeated definition. I haven't found the shadow of Winsock2.h for a long time. It is very strange. I checked the online post and didn't find this situation. Although others have the same mistake, most of them use it. STDAFX.H, inside the definition conflict, remember when writing VCs before, I can choose whether to support the network, but this time I built an empty Windows Console project, not used, so there is no way. I haven't had a result for a long time. Suddenly, I wanted to see _Win32_winnt = 0x500 This macro will bring what changes, so I checked this information, I didn't expect such a code in Windows.h.
#if (_WIN32_WINNT> = 0x0400)
#include
#include
#ELSE
#include
#ENDIF
Haha, no wonder the definition, change the included header file Winsock.h to Windows.h, and the problem is solved.
Next day
Error C2065: '_beginthreadex': undeclared Identifier
Error C2065: '_endthreadex': undeclared Identifier
Weird, how can I not support multi-threaded, just a previous project has also used these two functions, compares the project file, found that there is an option to be / mld, the original project is / MDD I changed directly in the project file, I found the problem solved, later
Project Settings-> C / C -> Code Generation-> Use Run-Time Library found that the multi-threaded selection is found. Compiling all over, I didn't expect Link or in addition to the problem. I have a function declaration and definition, but Link can't find it. I have a few error lnk2001: Unresolved External Symbol, and I don't know what the google is It seems that some reasons why it might generate Error LNK2001, no suitable me, and later helped me at the same time, it turned out that I used a document you wrote before, and the extension of the file must be .c
, Not .cpp
. General C
Compiler pair. C
File use C
Compilation, pair .cpp
Document use C
Method compilation (
The compiler will automatically define __CPLUSPLUS)
. C
I / O
Flow can only be in C
Compile work. There are two ways to solve the easiest way to change the file extension .cpp
. Or the function declaration in the header file is added like this.
#ifdef __cplusplus
Extern "C" {
#ENDIF
Function declaration #ifDef __cplusplus
}
#ENDIF
I used the first method and discovered a small problem with the setsockopt function. It turned out that the C compiler strictly caused the type conversion than C.
I finally ran up, it seems that VC is easy to use than GCC, but many things are hidden on the settings of pre-processing and tools, it is inconvenient, like that / MDD indicates multi-thread library that can be debug, fundamentally It can't be directly understood, unlike the use of GCC, all in Makefile is clear, even if you don't understand, it is easy to understand, it is also more convenient. However, in these development environment, there will not be too much, and it will be fine after encounter.