DLIB On visual studio 2015 throws a unresolved external error - c++

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.

Related

Avro C++ build error in Visual Studio 2015

in my current c++ project I need to use avro c++ serializer. Firstly I built boost 1.6.2 and based on it I build via Visual Studio 2015 the Avro-cpp.sln file as it is mentioned in avro relevant site. In my code I'm using the following include files
#include "avro/DataFile.hh"
#include "avro/Compiler.hh"
#include "avro/ValidSchema.hh"
#include "avro/Schema.hh"
#include "avro/Generic.hh"
#include "avro/Specific.hh"
However when I'm trying to build the project I get the following errors
error LNK2019: unresolved external symbol "public: void __thiscall avro::DataFileWriterBase::syncIfNeeded(void)
error LNK2019: unresolved external symbol "public: __thiscall avro::DataFileWriterBase::DataFileWriterBase(char const *,class avro::ValidSchema const &,unsigned int,enum avro::Codec)"
error LNK2019: unresolved external symbol "public: __thiscall avro::DataFileWriterBase::~DataFileWriterBase(void)" (??1DataFileWriterBase#avro##QAE#XZ) referenced in function "public: void * __thiscall avro::DataFileWriterBase::`scalar deleting destructor'(unsigned int)"
error LNK2019: unresolved external symbol "public: void __thiscall avro::DataFileWriterBase::close(void)"
error LNK2019: unresolved external symbol "public: void __thiscall avro::DataFileWriterBase::close(void)"
error LNK2019: unresolved external symbol "void __cdecl avro::compileJsonSchema(class std::basic_istream<char,struct std::char_traits<char> > &,class avro::ValidSchema &)"
error LNK2019: "public: void __thiscall avro::DataFileWriterBase::flush(void)"
I assume that the linker does not find the definition of the the specific classes DataFileWriterBase and compileJsonSchema .Since I'haven't worked with AVRO before I'd like to ask what libraries should I add in order for this problem to be solved? Do I have to insert the relevant cc files in my source code? I also built from Avro-cpp.sln file the avrocpp.dll and the avrocpp_s.dll, included them in my project but the problem remained the same. Does anyone has any idea since I haven't found any hint in either avro site or similar forums.
Hi again these are the new findings
I searched thoroughly and I probably found a possible cause , but I don't know how to move on. The problem seems to be in file Config.hh
#ifndef avro_Config_hh
#define avro_Config_hh
// Windows DLL suport
#ifdef _WIN32
#pragma warning (disable: 4275 4251)
#if defined(AVRO_DYN_LINK)
#ifdef AVRO_SOURCE
# define AVRO_DECL __declspec(dllexport)
#else
# define AVRO_DECL __declspec(dllimport)
#endif // AVRO_SOURCE
#endif // AVRO_DYN_LINK
#endif // _WIN32
#ifndef AVRO_DECL
#define AVRO_DECL
#endif
#endif
I think that AVRO_DYN_LINK is not defined and __declspec(dllexport) is not executed. So AVRO_DECL is defined and even though library lib is build with the function definitions they are exported and the error occur. Do you have any hint on the above analysis?

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.

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

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.

Read ini file C++ error

I have an ini file that has this info:
and this is my code:
#include "stdafx.h"
#include "iostream"
#include <stdio.h>
#include "IniReader.h"
#include "INIReader.h"
using namespace std;
int main(int argc, char * argv[])
{
INIReader reader("C:\SampleFile.ini");
if (reader.ParseError() < 0) {
cout << "Can't load 'test.ini'\n";
return 1;
}
std::cout << "Config loaded from 'test.ini': version="
<< reader.GetInteger("info", "CaptureDuration", -1) << "CaptureDuration"<<"\n"
<< reader.Get("info", "DayStart", `enter code here`"UNKNOWN") << ", email=";
cin.get();
return 0;
}
I also attached the INIReader header file that I found from this link:
https://code.google.com/p/inih/source/browse/trunk/cpp/INIReader.h
I want the code to print the integer and the string values that it got from the ini file. but I am getting Linker errors. How can I fix it?
Errors:
,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Get#INIReader##QAE?AV?$
1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall INIReader::ParseError(void)" (?ParseError#INIReader##QAEHXZ) referenced in function _main
#D#std##V?$allocator#D#2##std###Z) referenced in function _main
1>C:\Users\Owner1\Documents\Visual Studio 2008\Projects\inireader\Debug\inireader.exe : fatal error LNK1120: 4 unresolved externals
I do't see any lib file to link to this project, where should I get the lib files?
LNK2019 typically has one of the following reasons:
You forgot to link the proper lib file for your library (the ini reader in this case).
You linked the wrong lib file for your library (e.g. static vs. dynamic linking).
You forgot to add a cpp file for your library to your project.
You're mixing precompiled code that's meant for different platforms (like x86 and x64).
Edit:
In this particular instance, you'll have to add the file IniReader.cpp to your project, as it provides the missing functions.
Use Windows API like GetPrivateProfileString and WritePrivateProfileString for reading .ini files. It works fine and does not require any libraries. I used it for decades.
The simplest way is:
Copy all files of inih into your project directory (I think it is C:\Users\Owner1\Documents\Visual Studio 2008\Projects\inireader)
Drag all files of inih into your project in Visual Studio 2008.
Then press build button.
The error's reason is like #Mario said. You just compiled your cpp file, but not compile other cpp files that is necessory for your project. So you also need to compile all .cpp files in inih.
Note: I think you should read this to learn more about the compiling and linking of C.

How to Link to a .lib file in Visual C++ 2010? Without referencing the project?

I just have a problem that I have been trying to fix for the longest time.
I have a static library project in visual c++, and I want another project to be able to link to it. Up until now, I have simply been adding a reference to the static library project, which automatically links the library.
I want to be able to link to the library using only the header files and the .lib file. However, I get a "Unresolved external symbol" error.
I thought I was doing it right - I specified the include directory, the library directory, and went into the linker input properties and provided the lib as an additional dependency.
I am able to reference other static libraries this way (like SDL), so why do I get errors when I try to reference mine?
Thanks for the help.
Is the problem that its not referencing the actual lib file, or is something within the lib itself?
These are the error messages I get:
Error 2 error LNK2019: unresolved external symbol "public: void __thiscall XEngine::XCore::XScreen::init(class XEngine::XCore::XGame &)" (?init#XScreen#XCore#XEngine##QAEXAAVXGame#23##Z) referenced in function "void __cdecl XEngine::XEngineInit(class XEngine::XCore::XScreen &,class XEngine::XCore::XGame &)" (?XEngineInit#XEngine##YAXAAVXScreen#XCore#1#AAVXGame#31##Z) C:\Users\Xander Masotto\Documents\Visual Studio 2010\Projects\Pong\Pong\source.obj Pong
Error 3 error LNK2019: unresolved external symbol "public: __thiscall XEngine::XCore::XScreen::~XScreen(void)" (??1XScreen#XCore#XEngine##QAE#XZ) referenced in function "void __cdecl XEngine::XEngineInit(class XEngine::XCore::XGame &)" (?XEngineInit#XEngine##YAXAAVXGame#XCore#1##Z) C:\Users\Xander Masotto\Documents\Visual Studio 2010\Projects\Pong\Pong\source.obj Pong
Error 4 error LNK2019: unresolved external symbol "public: __thiscall XEngine::XCore::XScreen::XScreen(void)" (??0XScreen#XCore#XEngine##QAE#XZ) referenced in function "void __cdecl XEngine::XEngineInit(class XEngine::XCore::XGame &)" (?XEngineInit#XEngine##YAXAAVXGame#XCore#1##Z) C:\Users\Xander Masotto\Documents\Visual Studio 2010\Projects\Pong\Pong\source.obj Pong
Make sure that you are exporting the functions, classes, and variables in your library that you want exposed to other applications (i.e. your dll or exe). By default they are not exposed.
The ground work to do this is typically layed out when you create the project for your library.
#ifdef TESTLIB_EXPORTS
#define TESTLIB_API __declspec(dllexport)
#else
#define TESTLIB_API __declspec(dllimport)
#endif
With the code above generated during project creation there are only two more things for me to do to expose functions,classes, or variables:
1) Make sure that I have TESTLIB_EXPORTS defined as a preprocessor. Project settings: C++/Preprocessor/PreprocessorDefinitions
2) Use the TESTLIB_API define on each function,class, or variable i want exposed:
class TESTLIB_API Order {
void doSomething();
};