Visual Studio 2015 (C++) sqlite3.dll unresolved external symbol - c++

I cannot figure out how to get sqlite3.dll (or any dll for that matter) to work with my C++ project in Visual Studio.
The error message I get is LNK2001 unresolved external symbol sqlite3_open
Here's what I did so far:
I put the .dll in myProjectFoler/Resources/sqlite3.dll
I generated sqlite3.lib using Visual Studio Developer Command Prompt using a command lib /def:sqlite3.def
I referenced the directory with the lib in Project -> Preferences -> Linker -> General -> Additional Library directories, and then referenced the .lib in Project -> Preferences -> Linker -> Input-> Additional dependencies
I placed sqlite3.h in my project and #included it
(pretty much followed the instructions seen here)
Thank you for help

The issue is that by default the header file assumes that sqlite is linked statically, as opposed to dynamic linking to a dll.
This part of sqlite3.h is responsible for that:
#ifndef SQLITE_API
# define SQLITE_API
#endif
If you set a per-project define in project properties:
SQLITE_API=__declspec(dllimport)
this should resolve your link error.
Alternatively, you can put
#define SQLITE_API __declspec(dllimport)
right before where you #include sqlite3.h.

It's difficult to tell exactly why the problem occurred. There are lots of reasons which could cause LNK2001 error. MSDN contains good check list.
You could try to use /VERBOSE option to determine which files the linker references. Put this option in Project -> Preferences -> Linker -> Command Line -> Additional Options. Output should contains similar strings:
Searching e:\SQLite\sqlite-dll-win32-x86-3150100\sqlite3.lib:
Found _sqlite3_open
Referenced in ConsoleApplication2.obj
Loaded sqlite3.lib(sqlite3.dll)
Pay attention to the VS runtime libraries, there should be no mixup between Debug and Release libraries.

Related

Questions about third-party library(oat++) configuration in visual studio

As a beginner, I want to use oat++ as a third-party library in visual studio, but I encountered some configuration problems.
First I downloaded the source file of the oat++ project and opened it in visual studio and cmake and install.
Then I created a new project in visual studio and started running the first example of the official website.
First of all, it need to configure the preprocessing, I will configure the Include directory first.
What I did is:(my project name is web4)
Project -> Web4 properties -> configuration properties -> VC++ Directories
set the Include Directories include C:\Users\13925\Documents\cpp\oatpp\out\install\x64-Debug\include\oatpp-1.2.5\oatpp
That is great. The compiler can find the #include "file"
After that I'm having trouble,An error occurred when I tried to compile.
Error LNK2019 unresolved external symbol __imp_WSAStartup referenced in function....
By searching for information, it is found that the cause of this problem is that the related library is not included.
But I tried the online method and it didn’t solve the problem,so ask for help here.
The online approach is like this:
Project -> Web4 properties -> configuration properties -> VC++ Directories
set the Library Directories include C:\Users\13925\Documents\cpp\oatpp\out\install\x64-Debug\lib\oatpp-1.2.5
In C:\Users\13925\Documents\cpp\oatpp\out\install\x64-Debug\lib\oatpp-1.2.5 has three files:oatpp.lib、oatpp-test.liband a .hfiles.
Project -> Web4 properties -> configuration properties -> Linker -> Input
set Additional Dependencies include oatpp.lib and oatpp-test.lib
Compile after completing the above four steps and find that the problem is still not solved.
And the problen still unresolved external symbol.
I would be very grateful if you are willing to help.
As far as I'm concerned, the problem is you are not linking against the Ws2_32.lib library. To fix this you could try to add that to your additional dependencies tab of linker/Input settings for your project. And you could also try to add: #pragma comment(lib, "Ws2_32.lib")
Best Regards,
Jeanine

Problems linking Nlopt-2.4.2 in visual studio 2017

Some back story: I am trying to get the bolt-lmm software to compile on a Windows machine, because it would be a nice addition to the research group I am in. The developers of the software have only made a linux static executeable, but made the source code available. I am used to programming in R or python, and this is my first ever encounter with C++.
I have solved a fair bit of problems, but for some reason I have not been able to get visual studio to link properly with Nlopt-2.4.2.
I downloaded it
and followed the steps given there on how to install it.
I can tell I have done the same to link the Nlopt library to the project as is described in How to add additional libraries to Visual Studio project?
I still get errors like:
Error LNK2019 unresolved external symbol __imp__nlopt_create referenced in function "public: __thiscall nlopt::opt::opt(enum nlopt::algorithm,unsigned int)" (??0opt#nlopt##QAE#W4algorithm#1#I#Z) boltCompiler C:\Users\au483192\source\repos\boltCompiled\boltCompiler\NonlinearOptMulti.obj 1
(there are a total of 12 of this type of error, and an error link 1120, which just tells me there are 12 unresolved eternals.)
I hope this is enough information to provide a hint of what is going wrong.
I did some more digging, and it seems the linker needed more than just the folder for the .lib file.
This post sums it up:
Linking a static library to my project on Visual Studio 2010
Essentially you just need to tell the linker the placement of the lib and the actual name of the .lib file.
Hopefully this will help others who forgot/did not know that added library names manually could be needed for some libraries.
TL;DR:
open configuration properties for the project > linker > general
Then add the path to the .lib file in the "addition library directories" line
Then (still in configuration properties) go to linker > input
add the .lib file name to the "addition dependencies" line, e.g. libnlopt-0.lib (don't forget to separate with ";")

How do I resolve linker error LNK2019 while including "zlib" in my Visual Studio 2013?

I got the precompiled "lib" and "dll" from here: http://zlib.net/zlib128-dll.zip
I am compiling my project in x64.
I added directory into "Additional Include Directories"
I added the "zdll.lib" to Linker -> Additional Dependencies.
I added the library directory to Linker -> Additional Library Directories.
I also added the Post-Build Event "xcopy ..\oem\zlib\*.dll "$(TargetDir)"
But I still get the Linker error:
: error LNK2019: unresolved external symbol inflateInit_ referenced in function
Thanks.
IS that a 32-bit dll? If so, you'll have to obtain, or build your own, 64-bit version.
The linker error happens with the lib file, if you have the right headers it'll compile, if you have the right lib, it'll link, if you have the right dll, it'll run.

Linker Issues VS2015. LNK2019 and LNK2001 unresolved external symbol

I am trying to extend my knowledge of constrain programming and I want to build a simple example using google's or-tools in VS2015.
However I am constantly nagged by those linker errors. LNK2019 and LNK2001. Why is linking in VS so darn hard.
Google's or-tools comes in a perfect folder, with an include subfolder and lib subfolder with one single .lib file.
I have added Additional Library Dependencies.
Configuration Properties -> Linker -> General Additional Library Dependencies : C:\PATH\or-tools.VisualStudio2013-64b\lib
Set the Input under the Linker properties section.
Configuration Properties -> Linker -> Input Additional Dependencies : ortools.lib
Infomed VC++ where the include directory is.
Configuration Properties -> VC++ Directories : C:\PATH\or-tools.VisualStudio2013-64b
However it is still throwing link errors when building the solution. What am I missing here.
Thanks in advance.
edit:
spelling
Since the VS2013 and VS2015 compiler versions are incompatible, you have to build the lib from source. Though beware that this might entail a bit more work when linking with VS2015. Specifically I've had to manually resolve the following issues:
Change protobuf-3.0.0-beta-1 to protobuf-3.0.0-beta-2(bonus. not really necessary)
gflags 2.1.2 failed to compile due to a conflict of names around snprintf. To resolve this download the latest gflags version from GitHub and overwrite the one in %OR_TOOLS%\dependencies
Look up all VS solution files (.sln) in dependencies\sources\cbc-2.9.7 and convert to VS2015 format by simply double clicking them and following the instructions.
Add the following code to makefiles\Makefile.port
ifeq ("$(VisualStudioVersion)", "14.0")
VISUAL_STUDIO=2015
VS_RELEASE=v140
VS_COMTOOLS=140
else
...
endif
Replace Visual Studio 12 2013 with Visual Studio 14 2015
Rerun make third_party after each step.
Or you can just download the end result, linked on Windows 10 x64 VS2015 update 1. I've included the whole folder after running make third_party && make cc.

Installed MPI but still linker error LNK2019 appears

I've installed MS-MPIv5 from Microsoft and also the debugger for msmpi. In proejct properties in VS2012, I've changed C/C++ -> Additional include libraries adding "$(MSMPI_INC); $(MSMPI_INC)\x64" and also Linker -> All options->Additional Dependencies adding "msmpi.lib;", but VS is still giving me al lot of linker errors such as
error LNK2019: unresolved external symbol _MPI_Barrier#4
unresolved external symbol _MPI_Bcast#20
and so on, with all the mpi functions or type of variables. Is there something I forgot to change or add?
I haven't used 2012, but if it's similar to the older versions of VS then this detailed link may help. In general make sure to do these 3 things:
Add the "Additional Include Directories"
Add the "Additional Library Directories"
Add the "Additional Dependencies" (msimpi.lib)
It sounds like you may be missing the 2nd step?
Try $(MSMPI_INC)x64 (no \)
In my PC
MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include\