SQLite3 functions in DLL file cause unresolved external - c++

I am creating a DLL in Visual Studio 2008 which requires use of SQLite3. I have included the file sqlite3.h as found here. Right now my files only have one function, which simply takes one parameter, the database name, and opens it. My files are as follows:
DBOPEN.H
#include <string>
using namespace std;
__declspec(dllexport) bool OpenDatabase(std::string);
DBOPEN.CPP
#include "dbopen.h"
#include "sqlite3.h"
bool OpenDatabase(std::string name)
{
sqlite3 *database;
int isOpen = sqlite3_open(name.c_str(), &database);
}
It's worth noting I've never written DLLs before, and I was basing the formatting on what I've found at various sources online. When I try to build this, however, I get this error:
1>dbopen.obj : error LNK2019: unresolved external symbol _sqlite3_open referenced in function "bool __cdecl OpenDatabase(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?OpenDatabase##YA_NV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>C:\Users\me\Documents\Visual Studio 2008\Projects\dbopen\Debug\dbopen.dll : fatal error LNK1120: 1 unresolved externals
I'm honestly not really sure how to fix this. I've tried switching various things, changing function definitions, etc., but the sqlite3_open keeps causing errors. I noticed if I try to use other sqlite3 functions, they all give the same error, however the sqlite3 object definition works. Does anyone know how this can be fixed? Thanks in advance for the help!

Related

Accessing a function from another file (C++, QT) Unresolved external

I've been beating my head against this for too long now, and have researched everything I cannot find what's wrong.
I'm writing a GUI program in QT and have a few functions in some files external to the main program file, but within the project. The structure is something like this:
Source files:
main.cpp
mainwindow.cpp
signal.cpp
signalparse.cpp
header files:
mainwindow.h
signal.h
signalparse.h
Signal is an object that stores some data. Signalparse uses signal, parses a text file and reads it into signal. I tested this functionality on a barebones console application before putting it into my GUI program so I know it works(worked).
Now I find myself trying to call a function ReturnSignal from my SignalParse.cpp file inside my mainwindow.cpp file.
SignalParse.h is below:
#include<vector>
#include <iostream>
#include "signal.h"
void ParseLine(std::string*);
std::string ReturnTitle();
std::vector<Signal> ReturnSignal(std::string);
Showing I have declared ReturnSignal.
Inside SignalParse.cpp the function is defined as:
vector<Signal> ReturnSignal(string filename)
{
//does stuff
}
Inside mainwindow.cpp I declare an
std::vector<Signal> signalList;
to store the returned vector from ReturnSignal.
I then use
signalList = ReturnSignal(signalFilePath);
inside mainwindow.cpp to finally call this function and return my data. When commented out, there are no errors. However, this line causes the error:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class std::vector<class Signal,class std::allocator<class Signal> > __cdecl ReturnSignal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ReturnSignal##YA?AV?$vector#VSignal##V?$allocator#VSignal###std###std##V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##2##Z) referenced in function "private: void __cdecl MainWindow::on_file_open_triggered(void)" (?on_file_open_triggered#MainWindow##AEAAXXZ)
I cannot for the life of me figure out why this wont work. Does anyone have any ideas? I've been looking for hours now!
I would love to re-write the question to be more generally applicable if i find a solution, but at the moment I'm completely stumped.
Thanks a lot.
EDIT: Compiler being used is Microsoft Visual C++ Compiler 12.0
After some serious headaches I found a very simple solution. Having only really used either command line compilers or Visual Studio, this did not occur to me.
It turns out that in order to fix most of the unresolved external errors I was dealing with, I had to simply go into the build menu, clean my project and then "Run qmake". After this, all my unresolved externals disappeared and my program worked.
I don't know why it was so hard for me to find this information, hopefully it will be of help to someone in a similar spot.

C++ String passed to class constructor - linker errors

I'm a C# programmer working on a C++ project in VS 2008, trying to create an instance of an object and pass it a string as a parameter for the constructor. When I do this, I'm getting linker errors which I'm really struggling to diagnose.
The linker errors I'm getting are
2>TestMyProj.obj : error LNK2028: unresolved token (0A0002B9) "public: __thiscall myNamespace::myClass::myClass(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0myClass#myNamespace##$$FQAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "int __cdecl main(void)" (?main##$$HYAHXZ)
2>TestMyProj.obj : error LNK2019: unresolved external symbol "public: __thiscall myNamespace::myClass::myClass(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0myClass#myNamespace##$$FQAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "int __cdecl main(void)" (?main##$$HYAHXZ)
2>..\MyProj\TestMyProj.dll : fatal error LNK1120: 2 unresolved externals
from the project (TestMyProj) which tries to create an instance of the class. MyProj compiles fine. The code is as below:
MyProj.cpp
#include "MyProj.h"
namespace myNamespace
{
myClass::myClass(string inString){}
};
MyProj.h:
#pragma once
#include <string>
using namespace std;
namespace myNamespace
{
class myClass
{
public:
myClass::myClass(string inString);
};
}
The code where I'm trying to create an instance of the class MyClass is in another project within the same solution
TestMyProj.cpp:
#include <string>
#include "../MyProj/MyProj.h"
int main()
{
myNamespace::myClass("");
return 0;
}
I'm obviously misunderstanding something fundamental, probably about the nature of header files. I'm largely working to previously coded examples.
Can anybody point out what I'm doing wrong?
You need to link the projects together. In C#, when you reference a class it automatically links the assembly. With C++ you have to reference the class by including the .h file, and link the projects.
Solutions are just ways of collecting projects together and mean nothing to the compiler.
I'm a fan of statically linked libraries to be honest, but if you really want to create a dll, see https://msdn.microsoft.com/en-gb/library/ms235636.aspx and the section called "To use the functionality from the class library in the app".
mostly myproj.lib is not added to the library files list. in linker configuration.

configuration VS2010 for GreedyProjectionTriangulation

I have a code based on PCL 1.6, using functions as OrganizedFastMesh and Poisson, and it works well. But When I add this code to use GreedyProjectionTriangulation function VS2010 return this error:
*Error 51 error LNK2001: unresolved external symbol "private: virtual void __cdecl pcl::GreedyProjectionTriangulation::performReconstruction(class std::vector > &)" (?performReconstruction#?$GreedyProjectionTriangulation#UPointXYZ#pcl###pcl##EEAAXAEAV?$vector#UVertices#pcl##V?$allocator#UVertices#pcl###std###std###Z) C:...\pcl_surface.obj*
Does it need an additional file.lib to include?
Which ones? Or what else?
Thank you!
A few days ago,the same error occurred in my code (with two similar errors).
I added the lib file /lib/pcl_features_debug.lib to the linker-->input, and it works.
VS2010(X64) debug mode

Source code of CvCaptureFromFile(..)

I want to use the source code of the CvCaptureFromFile(..) function as I do not want to use OpenCV library functions in my project. So I went inside the function by pressing F10,F11 and I copied the things I needed and converted them into C code. Till now everything was ok.
But when I tried to run I am getting linking error inside the function icvIntFFMPEG(void)
the errors are as follows:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) void * __stdcall GetProcAddress(struct
HINSTANCE__ *,char const *)"
(__imp_?GetProcAddress##YGPAXPAUHINSTANCE__##PBD#Z) referenced in
function "void __cdecl icvInitFFMPEG(void)" (?icvInitFFMPEG##YAXXZ)
Error 2 error LNK2019: unresolved external symbol "struct HINSTANCE__
* __stdcall LoadLibrary(char const *)" (?LoadLibrary##YGPAUHINSTANCE__##PBD#Z) referenced in function "void
__cdecl icvInitFFMPEG(void)" (?icvInitFFMPEG##YAXXZ)
I copied everything as it is in the source code. Any idea where I am going wrong? How do I solve this error?
UPDATE: IF I wrap the header file (where I was coping the source code) inside an extern "C" something like this-
extern "C" {
#include "defination.h"
}
Then the first error is gone, and the error with loadLibrary changes to
error LNK2019: unresolved external symbol __imp__LoadLibrary#4 referenced in function _icvInitFFMPEG
OpenCv uses ffmpeg - which is a really big project. And ffmpeg uses some other tools behind curtains. You may want to go using ffmpeg, but to take the source code from ffmpeg itself is foolish - you will spend years fiddling with that code - really.
So, decide on a video input library - be it OpenCV, ffmpeg, Direct3D or whatever, and use it.
Do not cling yourself on the idea that 'you cannot use external libraries' because you can't go without them. It takes years to develop such a library - I am pretty sure you do not want to go that way.
Well, it seems your get unresolved calls to LoadLibrary()/GetProcAddress() functions that are inside Kernel32.dll. What IDE/project type are you using? Kernel32.lib should be linked in by default unless /NODEFAULTLIB is specified somewhere, at least as far as I remember. You can try to add #pragma comment(lib, "kernel32.lib") to the file where you copied the code, but without more info about your setup it is hard to answer what is causing this.

Error LNK 2019 unresolved external symbol from header file from my professor

So I'm pretty new to C++ programming and am taking a class on it but am having some trouble with an assignment because I am getting an error I can't seem to fix. The assignment is to create a composite class out of a number of classes using a string class the professor gave us. The problem I'm having is that I'm getting an unresolved external symbol error from the header file he gave us and I don't know why. I added the folder containing the header file and the associated cpp file using Properties -> C/C++ -> General -> Additional Include Directories and then used #include in the header file for my class but I'm getting 2 errors when I try to build it, the program compiles just fine. It's strange that I'm only getting 2 errors when there are many more functions in WCS_String that don't return an error.
Here are the error codes I'm getting:
1>Name.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall WCS_String::~WCS_String(void)" (??1WCS_String##UAE#XZ) referenced in function __unwindfunclet$??0Name##QAE#XZ$0
1>Name.obj : error LNK2019: unresolved external symbol "private: void __thiscall WCS_String::LocalCopy(char const *)" (?LocalCopy#WCS_String##AAEXPBD#Z) referenced in function "public: __thiscall WCS_String::WCS_String(char const *)" (??0WCS_String##QAE#PBD#Z)
If anyone could help me it would be greatly appreciated as I have run into a dead end with my limited programming knowledge. If you need any more information in order to help me please just ask.
If I were you I would just copy all the professor files to the project directory, and add both header and source files to it.
If you have .o or .obj files associated with your WCS_String class, you need to tell your linker where to find them.