anAppBuilder
asked on
Link C++ to Dll in VS2010
I'm learning SQLite on Win 7. They provide a .h and a .dll, but no .lib. Is there a way to link directly to a dll?
I looked here--am I missing something?
http://msdn.microsoft.com/en-us/library/vstudio/ms235636(v=vs.100).aspx
Or will I need to compile it from the source to a static library?
Thank you!
I looked here--am I missing something?
http://msdn.microsoft.com/en-us/library/vstudio/ms235636(v=vs.100).aspx
Or will I need to compile it from the source to a static library?
Thank you!
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you, nolanre
I tried to follow the reference you gave (or the VS 2010 version of it--they appear to be identical). It assumes that the code that uses the dll is in the same solution as the dll. "This will add the new project to the same solution as the dynamic link library." I didn't build the dll, so I don't have the solution it was built in. My project doesn't let me add the reference. Please see attached screenshot.
I tried to follow the reference you gave (or the VS 2010 version of it--they appear to be identical). It assumes that the code that uses the dll is in the same solution as the dll. "This will add the new project to the same solution as the dynamic link library." I didn't build the dll, so I don't have the solution it was built in. My project doesn't let me add the reference. Please see attached screenshot.
ASKER
Thank you, ve3ofa.
I'm not using .NET. This is a simple console app.
The first reference point out as I mentioned above, "there's no VS project/solution files included with SQLite". Does this mean there is no way to link with the dll?
I'm not using .NET. This is a simple console app.
The first reference point out as I mentioned above, "there's no VS project/solution files included with SQLite". Does this mean there is no way to link with the dll?
add the dll to your project references.
#include <windows.h>
#include <stdio.h>
// Import function that adds two numbers
extern "C" __declspec(dllimport) double AddNumbers(double a, double b);
int main(int argc, char *argv[])
{
double result = AddNumbers(1, 2);
printf("The result was: %f\n", result);
return 0;
}
From http://en.wikipedia.org/wiki/Dynamic-link_library.
ASKER
Thank you again, ve3ofa. Please tell me how to "add the dll to your project references". I click Project>References, and then add a new reference and get a window where there are no choices. Please see screenshot attached.
AddAReference.JPG
AddAReference.JPG
Did you follow the references: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
Package Types
There are a wide variety of downloadable packages on this page. Each of them is designed to meet the requirements of a particular development and/or deployment scenario.
The first step is to determine if the package is to be installed (or used) on a developer machine or a customer machine.
The source packages are intended primarily for people interested in studying the source code that corresponds to a particular release version of the project. The source packages contain no binaries. Those interested in studying the latest source code and/or tracking the unreleased changes should consider accessing the Fossil repository instead.
The setup packages are intended to be installed only on developer machines and then only when the design-time components for Visual Studio are required. In theory, they can be installed on customer machines as well; however, this type of deployment is not recommended.
The binary packages are intended to be used by developers in order to obtain the assembly binaries necessary for development and deployment of their applications onto customer machines via XCOPY deployment.
since you are targetting .net 4 Visual Studio 2010 versions
sqlite-netFx40-setup-bundl e-x86-2010 -1.0.84.0. exe or the x64 executable
sqlite-netFx40-setup-bundl e-x64-2010 -1.0.84.0. exe
Package Types
There are a wide variety of downloadable packages on this page. Each of them is designed to meet the requirements of a particular development and/or deployment scenario.
The first step is to determine if the package is to be installed (or used) on a developer machine or a customer machine.
The source packages are intended primarily for people interested in studying the source code that corresponds to a particular release version of the project. The source packages contain no binaries. Those interested in studying the latest source code and/or tracking the unreleased changes should consider accessing the Fossil repository instead.
The setup packages are intended to be installed only on developer machines and then only when the design-time components for Visual Studio are required. In theory, they can be installed on customer machines as well; however, this type of deployment is not recommended.
The binary packages are intended to be used by developers in order to obtain the assembly binaries necessary for development and deployment of their applications onto customer machines via XCOPY deployment.
since you are targetting .net 4 Visual Studio 2010 versions
sqlite-netFx40-setup-bundl
sqlite-netFx40-setup-bundl
ASKER
Thank you again, ve3ofa. I had not seen that page since I downloaded from here:
http://www.sqlite.org/download.html
It appears that I can either build directly from sqlite.c as www.sqlite.org seems to want me to do (and which seems to work) or use an appropriate .NET bundle from http://system.data.sqlite.org.
http://www.sqlite.org/download.html
It appears that I can either build directly from sqlite.c as www.sqlite.org seems to want me to do (and which seems to work) or use an appropriate .NET bundle from http://system.data.sqlite.org.
Your options did you try the sample code @ http://www.sqlite.org/quickstart.html
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you again, ve3ofa. The code I posted is a simplification of their C example with only the first SQLite call.
Thank you, jkr. I'll take a close look at your reference. It sounds like exactly what I'm looking for.
Thank you, jkr. I'll take a close look at your reference. It sounds like exactly what I'm looking for.
Well, I'd rather try to build both the DLL and th eimport library from the sources, since that might be less effort. Yet, if that doesn't work, this would be another way out...
ASKER
Well amazingly they gave me a .def file.... didn't know I could use it to build a lib. I'll give it a try.
ASKER
jkr provided the answer to the general question I asked....thank you!
ve3ofa provided a lot of useful information about SQLite...thank you!
ve3ofa provided a lot of useful information about SQLite...thank you!
ASKER
Just for the next person, a few more details.
This site provided useful info on how to configure and use the VS command line:
http://stackoverflow.com/questions/4245282/how-can-i-add-the-vs-command-prompt-to-visual-studio-2010-c-sharp-express
Here's the LIB command that worked. The "/LIBPATH:D:\SQLITE" may not be necessary.
This site provided useful info on how to configure and use the VS command line:
http://stackoverflow.com/questions/4245282/how-can-i-add-the-vs-command-prompt-to-visual-studio-2010-c-sharp-express
Here's the LIB command that worked. The "/LIBPATH:D:\SQLITE" may not be necessary.
LIB /LIBPATH:D:\SQLITE /DEF:D:\SQLITE\sqlite3.def /OUT:D:\SQLITE\sqlite3.LIB
ASKER
Another useful reference
http://www.askyb.com/cpp/establish-a-connection-to-sqlite-database-using-c/
http://www.askyb.com/cpp/establish-a-connection-to-sqlite-database-using-c/
Thanks for sharing!
First you add a reference. Then you include it in your code. You should then be able to call it.
Project -> Add Reference.
A DLL is already compiled. It's just a compiled bunch of methods.
It looks like from there they have some info on msdn about this.
http://msdn.microsoft.com/en-us/library/ms235636(v=vs.80).aspx