C Language Development Environment-compiling module

Source: Internet
Author: User

I am not familiar with the C language compiler in winodws. In winTC, there are some programs used to compile the C language. I am really not familiar with it and do not know what problems will happen. So I searched for Gcc in windows, but this port is really good. In windows, GCC and G ++ are integrated into mingw32 and can be connected to Gdb. Download and decompress the package, that is, the win32 version of the linux compilation tool.
Another problem is that makefile is automatically generated. in Linux, there are two tools, autoconf and automake, which can be implemented. After searching for the tool, the win32 version was not found in the morning. Instead of makefile, we can directly compile all. c files into. o files using gcc, and then concentrate them into a debug folder for link. This development environment is intended for beginners, and there should be no major problems without makefile.
In VC, The doscommand is called to call Gcc for compilation. Three call methods are found:
[Cpp]
System (LPCTSTR cmd );
[Cpp] view plaincopy
Uint winapi WinExec (
_ In maid,
_ In UINT uCmdShow
);
And
[Cpp]
HINSTANCE ShellExecute (
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
Lptstr lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

Their difference is that
System () will flash a dos window during the call and cannot be used.
WinExec cannot use operators, such as redirection and pipelines. However, you can use the second parameter to hide the window.
ShellExecute can also hide windows with powerful functions. At the beginning, I wanted to directly use shellExecute to call Gcc for compilation, but not the operator. Later, cmd was called and other commands were used as parameters. All commands under dos could be run.
Build_cmd = gcc + option + BUILD_OBJ + File_str + "2>" + dir + "\ stderr ";
Block_ShellExecute (NULL, "open", "cmd", "/c" + Build_cmd, project_dir, SW_HIDE );
However, you must note that the commands that need to be entered are not available and will wait infinitely. In addition, I encountered another problem. The shellExecute is not blocked, so the. o file in the first step may not be generated yet, and the link will run, causing an error. At first, I used to determine whether the. o file was completely generated. In this case, I had to first determine whether the compilation was wrong. This is not a good solution. Later, we found a better solution to achieve blocking by judging whether the process exits. The Code is as follows:
[Cpp]
Void block_ShellExecute (HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd)
{
SHELLEXECUTEINFO si;
ZeroMemory (& si, sizeof (si ));
Si. cbSize = sizeof (si );
Si. fMask = SEE_MASK_NOCLOSEPROCESS;
Si. hwnd = hwnd;
Si. lpVerb = _ T (lpOperation );
Si. lpFile = _ T (lpFile );
Si. lpParameters = _ T (lpParameters );
Si. lpDirectory = _ T (lpDirectory );
Si. nShow = nShowCmd;

ShellExecuteEx (& si );

DWORD dwExitCode;
GetExitCodeProcess (si. hProcess, & dwExitCode );
While (dwExitCode = STILL_ACTIVE)
{
Sleep (DWORD) 5 );
GetExitCodeProcess (si. hProcess, & dwExitCode );
}

CloseHandle (si. hProcess );
}
Author: AstrayLinux

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.