How to fix program errors in Win32 programs

Source: Internet
Author: User

Complete configuration process for VC ++ to operate MySQL (for Win32 programs)

I wrote an article about the configuration process of VC ++ for MySQL operations a few days ago. There are still some shortcomings. I will add them here.

It is because the previously mentioned configuration is no problem to run in the console application, but a problem occurs when you want to run the windows program (Win32 application or MFC. The following lists the error messages and solutions for program debugging:

(1) fatal error c1010: unexpected end of file while looking for precompiled header Directive

Error executing cl.exe

This error is common for beginners-I only encountered it because the pre-compiled header file is not added to the C ++ program file. There are two solutions:

1. Right-click the project name, select Settings, select the C/C ++ property page, and select precompiled from the catagory menu.
Header to set the option to no use or autometic. 2. Add # include "stdafx. H" to the beginning of the program file with an error (before adding statements to other header files, otherwise the connection to other header files will be affected ". For more information, refer to the http://www.cppblog.com/wrhwww/archive/2009/02/20/74374.aspx.

(2) c: \ Program Files \ Microsoft Visual Studio \ vc98 \ include \ mysql_com.h (184): Error c2146: syntax error: Missing '; 'before identifier
'Fd'

C: \ Program Files \ Microsoft Visual Studio \ vc98 \ include \ mysql_com.h (184): Error c2501: 'socket': Missing storage-class or type specifiers

C: \ Program Files \ Microsoft Visual Studio \ vc98 \ include \ mysql_com.h (184): Error c2501: 'fd ': Missing storage-class or type specifiers

C: \ Program Files \ Microsoft Visual Studio \ vc98 \ include \ mysql_com.h (354): Error c2065: 'socket': Undeclared identifier

C: \ Program Files \ Microsoft Visual Studio \ vc98 \ include \ mysql_com.h (354): Error c2146: syntax error: Missing ') 'Before identifier's'

C: \ Program Files \ Microsoft Visual Studio \ vc98 \ include \ mysql_com.h (355): Error c2059: syntax error :')'

Error executing cl.exe.

Win32data.exe-6 error (s), 0 warning (s)

I believe many people have encountered this error.

According to the error message, check the variable definition Statement of mysql_com.h with my_socket FD. According to general experience, it can be inferred that the variable type my_socket is not defined.

Then, click "go to definition of my_socket" and choose "go to definition of my_socket" from the shortcut menu. Finally, you can find this code in MySQL. h:

# Ifndef my_socket_defined

# Ifdef _ win __

# Define my_socket socket

# Else

Typedef int my_socket;

# Endif/* _ win __*/

# Endif/* my_socket_defined */

By interpreting pre-compiled statements, we can release the my_socket_defined statement without declaration, but _ win _ has been declared. That is to say, my_socket has already been declared as socket.

As a result, we can view the socket definition on the upstreaming stream. Similar to the previous method, we can find that the 35 rows in Winsock. h are: typedef.
U_int socket;

In addition, in the file just now, MySQL. H has the following code in line 34:

# Ifdef _ KP __

# Include <Winsock. h>/* For Windows */

# Endif

Therefore, we can infer that:My_socket is not declared => socket is not declared =># include <Winsock. h> is not run to =>
_ KP _ Not declared

So the solution came out:

1. Add the following pre-compiled statement to the beginning of the mysql. h file (before # include "mysql. h:

# Ifndef _ KP __

# DEFINE _ KP __

# Endif

That is, the Declaration _ KP _ enables the program to execute# Include <Winsock. h>.

2. directly add typedef unsigned int my_socket; In mysql_com.h to declare my_socket.

However, I prefer to use the first method.

Since then, the problem has been solved. Win32 or MFC programs can use MySQL APIs to operate MySQL Databases normally.

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.