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.
Related
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.
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.
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!
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.
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.