有没有办法在mfc程序中使用SQL C ++库? [英] Is there any way to use SQL C++ library in mfc program?

查看:85
本文介绍了有没有办法在mfc程序中使用SQL C ++库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我在c ++控制台环境中为我的数据库任务编写了一个库

然后当我将这个库添加到我的MFC程序时,它给了我一些链接器错误:

LNK2001未解析的外部符号_SQLSetEnvAttr @ 16

LNK2001未解析的外部符号_SQLAllocHandle @ 12

我想知道是否有办法链接我的MFC程序到我的sql数据库;

任何评论赞赏。



我尝试过:



我的程序在控制台应用程序中正常工作

hi ALL
I wrote a library for my database tasks in c++ console environment
then when I added that lib to my MFC program it gives me some linker errors:
LNK2001 unresolved external symbol _SQLSetEnvAttr@16
LNK2001 unresolved external symbol _SQLAllocHandle@12
I want to know if there was a way to link my MFC program to my sql database;
any comment appreciated.

What I have tried:

my program work fine in console application

推荐答案

你必须将你的应用程序链接到包含这些函数的库是 odbc32.lib 就像你为你的控制台应用程序所做的那样。



你可以在 Linker的项目设置中做到这一点 - 输入 - 附加依赖项或在您的一个源文件中使用 pragma 语句:

You have to link your application with the library containing these functions which is odbc32.lib like you have done for your console application.

You can do that in the project settings at Linker - Input - Additional Dependencies or using a pragma statement in one of your source files:
#pragma comment(lib, "odbc32.lib")


你可以包含C ++库,但是存在很多陷阱。您是否已将lib文件包含在链接器设置中(或代码中的链接)。二进制文件还必须匹配x32或x64。如果dll使用MFC,最好静态链接它(或者你使用MFC dll typ)。



另一个大问题是,你需要导出函数在dll中以正确的方式。阅读此 Microsoft文档您有哪些选项。通常

You can include C++ library into, but there are a lot of pitfalls. Have you include the lib file into the linker settings (or link in code). The binaries must also match x32 or x64. If the dll uses MFC it is better to static link it (or you use the MFC dll typ).

Another big problem is, that you need to export the function in the dll in the correct way. Read this Microsoft documentation which options you have. Normally the
__declspec(dllexport)

是最好的方式。


这篇关于有没有办法在mfc程序中使用SQL C ++库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆