SQLite Forum

Where to put dll in VisualStudio?

Where to put dll in VisualStudio?

(1) By PeterR on 2020-10-20 07:48:59 [link] [source]

This is driving me crazy. Using VisualStudio on Win 10 for a C++ program with sqlite. No matter where I put sqlite3.dll, VS can't find it. Where should it go? In desperation I've put copies of it in all the likely places but no luck. Googling produces answers that seem to be for Linux (that'll come later for me) but not for Windows. Neither have I found a thread here that seems to answer the problem.  Your help would be greatly appreciated.

(2) By Keith Medcalf (kmedcalf) on 2020-10-20 08:42:33 in reply to 1 [link] [source]

The DLL goes in the same directory as the executable or in a directory in the path (unless you have specified otherwise).

Are you sure that the DLL is the same model as the executable?

32-bit DLLs will only be loaded in 32-bit processes and ignored by 64-bit processes.
64-bit DLLs will only be loaded in 64-bit processes and ignored by 32-bit processes.
Windows also does some weird farting about with the SYSTEM / SYSTEM32 / SYSWOW64 / Program Files / Program Files (x86) directories so it is best to not ever put anything there unless you know what you are doing.

This applies notwithstanding that the "filename" is the same. More specifically you can have a directory called C:\DLL32 in which the 32-bit version of the DLL is located, and a directory called C:\DLL64 in which the 64-bit DLL is located, with both having the identical name "sqlite3.dll", and put both directories in the path (in any order), and Windows will (only) load whichever one is the correct model and not even try to load the "wrong one". If no "right one" is found then it will tell you that it was not found but will not tell you that it found the "wrong one" (because it didn't).

(3) By Warren Young (wyoung) on 2020-10-20 09:14:59 in reply to 2 [link] [source]

Microsoft has a long article explaining these details and more. The rules are now complicated enough that it isn't worth trying to memorize them all, for most developers.

(4) By PeterR on 2020-10-20 10:01:41 in reply to 2 [source]

Hi Keith:

Thanks for the reply. They're both 32-bit versions, and the system path includes the directory with the dll. No luck - still getting "unresolved external symbol" from the linker for every mention of sqlite3.


(5) By PeterR on 2020-10-20 10:03:37 in reply to 3 [link] [source]

Hi Warren:

Yep, it's a long article. Trying to make sense of it. MS doc writers must be paid by the word.


(6) By Bill Wade (wwade) on 2020-10-20 12:38:12 in reply to 4 [link] [source]

.dll is loaded at runtime.

You are showing a link-time error message.

The linker wants a .lib as input, at link-time.

To get the .lib, open a visual studio command prompt (this will give a console window that has "lib.exe" on its path) Go to the directory containing sqlite3.def (probably the same one containing sqlite3.dll). Run: lib /def:sqlite3.def /out:sqlite3.lib

Add sqlite3.lib as a source file to our project (the same way you add a .cpp file) xor Add sqlite3.lib as a (Linker->Input->Additional Dependencies in the IDE). Make sure the directory containing sqlite3.lib is in your list of Additional Library Directories).

(7) By PeterR on 2020-10-20 16:37:43 in reply to 6 [link] [source]

THANK YOU BILL! That worked just fine. Now to get the rest of the program working...