您的位置:首页 > 编程语言 > C语言/C++

VC++控制台程序使用Mysql,以及和MFC程序的兼容问题,工具VS2010ultimate

2014-03-08 17:21 531 查看
使用总结:

1.#include<mysql.h>之前一定要加上#include<windows.h>否则会产生如下错误:

1>d:\dev\mysql50\include\mysql_com.h(175): error C2146: 语法错误: 缺少“;”(在标识符“fd”的

前面)

1>d:\dev\mysql50\include\mysql_com.h(175): error C4430: 缺少类型说明符 - 假定为 int。注意:

C++ 不支持默认 int

1>d:\dev\mysql50\include\mysql_com.h(175): error C4430: 缺少类型说明符 - 假定为 int。注意:

C++ 不支持默认 int

1>d:\dev\mysql50\include\mysql_com.h(339): error C2065: “SOCKET”: 未声明的标识符

1>d:\dev\mysql50\include\mysql_com.h(339): error C2146: 语法错误: 缺少“)”(在标识符“s”的

前面)

1>d:\dev\mysql50\include\mysql_com.h(340): error C2059: 语法错误:“)”

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(24): fatal error

C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared

dll version. Please #define _AFXDLL or do not use /MD[d]

1> testMdApi.cpp

1>d:\dev\mysql50\include\mysql_com.h(175): error C2146: 语法错误: 缺少“;”(在标识符“fd”的

前面)

1>d:\dev\mysql50\include\mysql_com.h(175): error C4430: 缺少类型说明符 - 假定为 int。注意:

C++ 不支持默认 int

1>d:\dev\mysql50\include\mysql_com.h(175): error C4430: 缺少类型说明符 - 假定为 int。注意:

C++ 不支持默认 int

1>d:\dev\mysql50\include\mysql_com.h(339): error C2065: “SOCKET”: 未声明的标识符

1>d:\dev\mysql50\include\mysql_com.h(339): error C2146: 语法错误: 缺少“)”(在标识符“s”的

前面)

1>d:\dev\mysql50\include\mysql_com.h(340): error C2059: 语法错误:“)”

1>

1>生成失败。

2.#include "afxdialogex.h" //为了调用AfxMessageBox引入

#include <windows.h> //为调用MessageBox和Beep引入

3. fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version)

requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

solution:项目-〉属性-〉use of MFC 改成use MFC in a share dll

错误已经很明白告诉你了:

#error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll

version. Please #define _AFXDLL or do not use /MD[d]

使用多线程动态连接运行时库的MFC程序, 需要使用MFC动态连接库.

改工程设置:

Project|Properties|Configuration Properties|General|Use of MFC : Use MFC in a

Shared DLL

4.

fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include

<windows.h>

WINDOWS.H already included. MFC apps must not #include <windows.h>

你用MFC就不用#include <windows.h>这个了!

如果是重用你在里stdafx.h加了#include <windows.h>,别的地方就不要再#include <windows.h>,只要

有#include "stdafx.h"就可以了!

按下面试试:

1. 所有".cpp"文件加入#include"stdafx.h"

2.你建的工程是console? 在工程设置中,点击link标签,底部:subsystem:后的console改成windows

good luck!

猜想原因可能如上所述,我的解决方法是,将包含有#include “windows.h"的头文件放在所有包含

的头文件的最后面,这样使得对afxv_w32文件

的编译处理发生在先,这样,由于在afxv_w32.h中已经包含了windows.h,那么宏_WINDOWS_将被定义,

后继的#include "windows.h"语句将形同虚设,

上面的编译报警也不会发生了。我觉得这种处理要比将所有的#include "windows.h”语句删掉要好

一点。



一句话,编译器必须在编译windows.h之前编译afxv_w32.h,因为我不是十分清除什么时候afxv_w32.h会

被编译,所以我将可能包含有#include "windows.h"的头文件放在其他头文件之后#include。

I get an error when trying to compile a small c++ program

Error 87 fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include

c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxv_w32.h 16

I made sure that the windows.h was not included in any of the project files I have. I am

using a visual studio 2008 IDE

Any reason why ?

reason why is because something is including Windows.h: the compiler is not lying to you.

Go to project Properties->Configuration Properties->C/C++->Advanced and set Show Includes to

Yes. Then build, and the compiler will show you a list with every included file found, and

in the order it finds it, hereby telling you which file eventually includes windows.h

try and include afxcoll.h before stdafx.h. I had the same problem and it fixed it. See
http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/2ab6862f-0d90-467a-b283-
f62f6aef96fe/ for the original discussion.

including afxcol.h before atlstr.h in my stdafx.h file fixed the problem for me – Sean Jan

9 at 16:58

add comment

Visual Studio by default will defile your program with a precompiled headers file, which may

contain something which includes something which includes windows.h . Be sure to check in there.

一句话,编译器必须在编译windows.h之前编译afxv_w32.h,因为我不是十分清除什么时候afxv_w32.h会

被编译,所以我将可能包含有#include "windows.h"的头文件放在其他头文件之后#include。



Ps:我也遇到了这个错误,调整头文件的编译顺序就可以解决,以上的解释很有道理,就贴到这里了^_^

5.

1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning

MSB8012: TargetPath(C:\Documents and Settings\Administrator\桌面\temp\行情开发实例

\bin\testMdUserApi.exe) 与 Linker 的 OutputFile 属性值(C:\Documents and

Settings\Administrator\桌面\temp\行情开发实例\bin\testMdApi.exe)不匹配。这可能导致项目生成不

正确。若要更正此问题,请确保 $(OutDir)、$(TargetName) 和 $(TargetExt) 属性值与 %

(Link.OutputFile) 中指定的值匹配。

1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(992,5): warning

MSB8012: TargetName(testMdUserApi) 与 Linker 的 OutputFile 属性值(testMdApi)不匹配。这可能导

致项目生成不正确。若要更正此问题,请确保 $(OutDir)、$(TargetName) 和 $(TargetExt) 属性值与

%(Link.OutputFile) 中指定的值匹配。

VS2010/VS2012 waring MSB8012问题解决

大概意思是输出文件跟链接器的输出文件的配置不匹配。

解决方法如下,进入该项目的项目属性设置:

1、“配置属性”-》“常规”,“输出目录”和“中间目录”都改为:$(SolutionDir)

$(Configuration)\

2、“配置属性”-》“链接器”-》“常规”,“输出文件”改为:$(SolutionDir)$(Configuration)

\$(TargetName)$(TargetExt)

于是Google一下, 结果在这里发现了大家都发现同样的问题

我这里的编译习惯是这样的, 调试版无论dll, lib还是exe,都在工程名后加d加扩展名组成最后的名称,例



cored.lib engined.lib , Release版本没有d

因此,为了避免这个warning,只用将调试版的General节点上Target Name的值改为$(ProjectName)d

而有些工程的Librarian或者Link分支的Output File的值在转换升级的过程中会被修改. 同样可以统一修

改为vs2010的风格$(OutDir)$(TargetName)$(TargetExt)

用C语言做数据库操作还真不多,一般都选择文件操作来搞定。

最近一个项目需要用到MYSQL,就去看了下mysql之c api.

基本上都是一样的,说白了就是一个应用层的协议。正因为做的机会不多,所以要写下来,免得以后忘记

了。

还有很多api,不再一一介绍,大部分信息都在MYSQL_RES MYSQL这两个结构体中。

具体可以参考mysql官方网站:
http://dev.mysql.com/doc/refman/5.1/en/c.html

突然发现官方网站资料好全面,貌似比任何书都要好。

如果要insert或者update,只需要修改具体的sql既可。

具体的操作都是通过mysql_query这个函数来搞定。

现在来讲编译的方法吧,这里我们需要.h以及.so库。

我们可以在
http://dev.mysql.com/downloads/connector/c/6.0.html

下载Connector/C。

简单的方法就是:

把里面include的东西拷贝到/usr/include/mysql/下面去,这样编译的时候就不需要加-I了,然后把lib

下面的东西拷贝的/usr/lib/下去。

gcc具体的编译方法:gcc ***.c -o *** -lmysqlclient
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐