Microsoft Visual Studio C++ 2013 Linking Error (when using SQLite wrapper) - c++

Here is my main loop:
#include <string>
#include <stdio.h>
#include <iostream>
#include <sqlite3.h>
using namespace std;
int main()
{
sqlite3 *database;
sqlite3_open("db.sql", &database);
return 0;
}
When I compile it, it throws a linking error. Errors are as follow:
1>Students.obj : error LNK2028: unresolved token (0A000451) "extern "C" int __cdecl sqlite3_open(char const *,struct sqlite3 * *)" (?sqlite3_open##$$J0YAHPBDPAPAUsqlite3###Z) referenced in function "int __cdecl main(void)" (?main##$$HYAHXZ)
1>Students.obj : error LNK2019: unresolved external symbol "extern "C" int __cdecl sqlite3_open(char const *,struct sqlite3 * *)" (?sqlite3_open##$$J0YAHPBDPAPAUsqlite3###Z) referenced in function "int __cdecl main(void)" (?main##$$HYAHXZ)
1
How can I solve it? I should say that in Microsoft Visual Studio 2013, I have disabled pre-compiled headers, added a directory for my SQL.sql in Linker->additional directories, also added my headers and cpp files to aditional # include directories.

You will need to include the source file(s) that came with sqlite3 in your project. (Or, you could create a library that you would include with your project, but that's a slightly more complex answer.)
Anyway, yea, you probably have a file called "sqlite.c" -- just include that with your project so that it compiles as well. You may still have some other errors/warnings to resolve; however, I think that will take care of the unresolved externals.
If you have .lib or .dll files instead of actual source, then you'll just need to include those in your project similarly.

Related

DLIB On visual studio 2015 throws a unresolved external error

I'm trying to run the face detection example provided by dlib. I have set up my library directories and my include folders. I've included source.cpp in the project, and have added the files from the externals folder into it as well. When I run the program it said to enable jpeg support by defining jpeg support, which i did, but then it wont compile and provide 2 similar errors about an unresolved external.
unresolved external symbol "public: __thiscall dlib::jpeg_loader::jpeg_loader(class std::basic_string,class std::allocator > const &)" (??0jpeg_loader#dlib##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "void __cdecl dlib::load_jpeg > >(class dlib::array2d > &,class std::basic_string,class std::allocator > const &)" (??$load_jpeg#V?$array2d#EV?$memory_manager_stateless_kernel_1#D#dlib###dlib###dlib##YAXAAV?$array2d#EV?$memory_manager_stateless_kernel_1#D#dlib###0#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) DLIBtemplate
This is my code header:
#define DLIB_JPEG_SUPPORT
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
using namespace dlib;
using namespace std;
You have to define DLIB_JPEG_SUPPORT for all your .cpp files, not just one of them. You set it as a compiler setting in your project, not by writing #define in one file.

error LNK2019: unresolved external symbol "extern "C" what is this error?

i was trying to wrap cimg library inside c++/clr and when i try to build it i get a bunch of Link errors.
Error 20 error LNK2028: unresolved token (0A0002AC) "extern "C" int __stdcall DestroyWindow(struct HWND__ *)" (?DestroyWindow##$$J14YGHPAUHWND__###Z) referenced in function "public: void __thiscall cimg_library::CImgDisplay::_desinit_fullscreen(void)" (?_desinit_fullscreen#CImgDisplay#cimg_library##$$FQAEXXZ) c:\Users\serakpc\documents\visual studio 2012\Projects\CimgWrapper\CimgWrapperCLI\Stdafx.obj CimgWrapperCLI
source code in Stdafx.h
#pragma once
#include "cimgheader\CImg.h"
Just including the header isn't enough. If you have a static compiled library, you need to include it in your solution so the linker will be able to find the binary code and produce an executable. If you have source code of the library, you need to include it in the solution and compile it with your own code.

C++/CLI LNK2028 when trying to use static lib of another library

I am having a LNK2028 error when I try to build my C++/CLI dll. I am using a static lib called pano13 in my program, and I am using one method of it. Everything in my program is fine except the one method call I make to the library, where I get these exact two exceptions.
Error 21 error LNK2028: unresolved token (0A00013B) "int __cdecl panoCreatePanorama(struct fullPath * const,int,struct fullPath *,struct fullPath *)" (?panoCreatePanorama##$$FYAHQAUfullPath##HPAU1#1#Z) referenced in function "public: int __clrcall Surgeon::Stitcher::StitchImage(class System::Collections::Generic::List<class System::String ^> ^,class System::String ^)" (?StitchImage#Stitcher#Surgeon##$$FQ$AAMHP$AAV?$List#P$AAVString#System###Generic#Collections#System##P$AAVString#6##Z) C:\Users\ndean_000\Documents\Visual Studio 2012\Projects\C#\CameraTest\Surgeon\Surgeon.obj Surgeon
Error 22 error LNK2019: unresolved external symbol "int __cdecl panoCreatePanorama(struct fullPath * const,int,struct fullPath *,struct fullPath *)" (?panoCreatePanorama##$$FYAHQAUfullPath##HPAU1#1#Z) referenced in function "public: int __clrcall Surgeon::Stitcher::StitchImage(class System::Collections::Generic::List<class System::String ^> ^,class System::String ^)" (?StitchImage#Stitcher#Surgeon##$$FQ$AAMHP$AAV?$List#P$AAVString#System###Generic#Collections#System##P$AAVString#6##Z) C:\Users\ndean_000\Documents\Visual Studio 2012\Projects\C#\CameraTest\Surgeon\Surgeon.obj Surgeon
I am including the lib file in the project settings, and I even added the #pragma comment statement for including the library, however I am getting this error. I understand that it has to do with the mixing of native and managed C++, however I am not compiling the program with clr/pure, it is being compiled with the default clr compilation of /clr. Anyone have any ideas how to fix it?
By the way, I solved this a WHILE ago, but I should probably say what the issue was. The panotools library is a C library, not a C++ library. I didn't know that C libraries needed the extern C directive to be used in C++. So all I had to do to fix my problem was
extern "C"
{
#include <panorama.h>
}
Where panorama.h is the include file for the panotools C library. I've always wondered what extern C was for and now I finally understand its purpose.

Help on jrtplib and jthread

I have some link error problems when trying to compile using jrtplib and jthread on my simple project. The errors are:
Error 4 fatal error LNK1120: 3 unresolved externals C:\Users\Chicko\Desktop\tryout\Debug\tryout.exe
Error 1 error LNK2019: unresolved external symbol "public: virtual __thiscall RTPSession::~RTPSession(void)" (??1RTPSession##UAE#XZ) referenced in function _wmain tryout.obj
Error 2 error LNK2019: unresolved external symbol "public: __thiscall RTPSessionParams::RTPSessionParams(void)" (??0RTPSessionParams##QAE#XZ) referenced in function _wmain tryout.obj
Error 3 error LNK2019: unresolved external symbol "public: __thiscall RTPSession::RTPSession(class RTPRandom *,class RTPMemoryManager *)" (??0RTPSession##QAE#PAVRTPRandom##PAVRTPMemoryManager###Z) referenced in function _wmain tryout.obj
and here is my main program:
// tryout.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <rtpsession.h> //Confused to put "" or <>
#include <rtpsessionparams.h>
#include <rtpudpv4transmitter.h>
int _tmain(int argc, _TCHAR* argv[])
{
RTPSession session;
RTPSessionParams sessionparams;
RTPUDPv4TransmissionParams transparams;
sessionparams.SetOwnTimestampUnit(1.0/8000.0);
transparams.SetPortbase(8000);
return 0;
}
For your information, I do not import any header file from those libraries into my project. I use additional include libraries in the project setting and put `"..\jlib\jthread-1.2.1\src";"..\jlib\jrtplib3.8.2\src" (this is the folder where all the headers are stored). How do I fix this? Where should i put jrtplib.lib and jthread.lib? Please help...
Have you added jrtplib.lib and jthread.lib under your project linker options?
You can do this on the project property page under
"Configuration properties->Linker->Input->Additional Dependencies" and make sure that the directory that contains the lib files has been added to your library path: Either on the project properties
"Linker->General->Additional Library Directories"
or under the global VS settings (Doesn't apply to VC2010)
"Tools->Options" "Projects and Solutions->VC++ Directories->Library Files"
Under VC2010 you'll have to edit the property sheet of the project.
I see that it's a bit late to answer and I'm not so expert on Windows (I'm more a Linux user), but some day ago I've tried JRTPLIB on Windows and I had the same problem when I compiled the example in release mode and the lib in debug mode (I see that you use the debug mode). Hope it can help.

C++ linker unresolved external symbol (again;) from other source file *.obj file. (VC++ express)

I'm back to C/C++ after some break.
I've a following problem:
I've a solution where I've several projects (compilable and linkable).
Now I need to add another project to this solution which depends on some sources from other projects.
My new project compiles without any problems (I've added "existing sources" to my project).
the error:
1>Linking...
1>LicenceManager.obj : error LNK2019: unresolved external symbol "int __cdecl saveLic(char *,struct Auth *)" (?saveLic##YAHPADPAUAuth###Z) referenced in function "public: void __thiscall LicenceManager::generateLicence(int,char *)" (?generateLicence#LicenceManager##QAEXHPAD#Z)
1>LicenceManager.obj : error LNK2019: unresolved external symbol "void __cdecl getSysInfo(struct Auth *)" (?getSysInfo##YAXPAUAuth###Z) referenced in function "public: void __thiscall LicenceManager::generateLicence(int,char *)" (?generateLicence#LicenceManager##QAEXHPAD#Z)
Functions saveLic, and getSysInfo are defined in files which I've added to my new project from existing ones. There is object file created during compilation with those functions in target dir, but my LicenceManager class doesn't want to link.
I use some
extern "C" , and #pragma pack
somewhere, but no more fancy stuff. I think every directory, lib and other necessary dependencies are visible in settings for this project.
Thanks for any advice.
Seems like you need to make sure the functions are declared properly as C functions:
#ifdef __cplusplus
extern "C" {
#endif
int saveLic(char *,struct Auth *);
void getSysInfo(struct Auth *);
#ifdef __cplusplus
}
#endif
In a header file included by LicenceManager.cpp.