Click here to Skip to main content
14,934,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 6-Aug-18 22:32pm

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:
C++
#pragma comment(lib, "odbc32.lib")
   
Comments
KarstenK 7-Aug-18 13:50pm
   
The error message sounds that he including the lib BUT the exported names arent matching. Thats why my answer includes some more tips.

PS: if it doesnt help we need more information.
Jochen Arndt 7-Aug-18 14:15pm
   
My solution has been accepted. I guess he just forgot to add the library to the dependencies. Note also that it is a MS system library and not a self written one.
KarstenK 8-Aug-18 4:43am
   
I see - so simple ;-)
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
C++
__declspec(dllexport)
is the best way.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900