error LNK2019: unresolved external symbol due to helper library - c++

I think the issue is with a function ConvertToUpperCase included in a helper library used in my CS course. I am trying to write something for my experiment but I learned with the helper library - so I don't know what to do without it.
The full error error:
LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ConvertToUpperCase(class std::basic_string,class std::allocator >)" (?ConvertToUpperCase##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V12##Z) referenced in function "public: bool __thiscall Lexicon::containsPrefix(class std::basic_string,class std::allocator >)" (?containsPrefix#Lexicon##QAE_NV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
The function is included in strutils.h and explained here
Sample code:
#include "stdafx.h"
#include <cstdlib>
#include <string>
#include <iostream>
#include <set>
#include <fstream>
#include "genlib.h"
#include "strutils.h"
#include "simpio.h"
#include "set.h"
#include "lexicon.h"
using namespace std;
/* Function: AddWord1
* -----------------
* This function prompts the user for a code and then
* coverts entry to upper case and adds this word to the code list passed in.
*/
void AddWord1(Lexicon & lex)
{
cout << "Please enter activity code to add: ";
string word = ConvertToUpperCase(GetLine()); //may need to remove for code
lex.add(word);
cout << word << " added to code list." << endl;
}
Clarification:
yes, this was working code in 2009 and 2010 - so it was implemented.
the library was a .lib and I am now using the sourceForge version.
VS 2008, it last was working from a VS2005 compile, I have tried VS2005 and VS2011BETA but still have errors.
I am trying to make sure the appropriate cpp files are added to the project; I think they are. My genlib.cpp is dated 2011 and is different than the github.com/b33tr00t/cs106lib version which is for Linux users, so it makes sense that there are some differences.

There should be a library containing the compiled code as well as the header that you have. You need to add that library (a .lib or .obj file) to your project - specifically you need to include it in the linker settings.
If you don't have that then you might have one or more C++ source files defining those functions - you could add those to the project.
If you have none of those then you have a problem, I'm afraid.

If you don't have access to that library anymore (since you may no longer be in the class), you can write your own ConvertToUpperCase function using one of the techniques from this question.

Related

Creating a C++ .Net Core wrapper for native library results in error LNK2028

I'm trying to create a managed (.net core) C++/CLI wrapper for a native library (Srt) but when referencing methods in the native lib I'm getting 2 build errors. I've referenced the headers srt.h from the native library, tried calling a method named srt_cleanup but get this on build:
error LNK2028: unresolved token (0A00000B) "extern "C" int __cdecl srt_cleanup(void)" (?srt_cleanup##$$J0YAHXZ) referenced in function "public: void __clrcall HeliosMediaStreamCliSrt::SrtReceiver::Stop(void)" (?Stop#SrtReceiver#HeliosMediaStreamCliSrt##$$FQE$AAMXXZ)
error LNK2019: unresolved external symbol "extern "C" int __cdecl srt_cleanup(void)" (?srt_cleanup##$$J0YAHXZ) referenced in function "public: void __clrcall HeliosMediaStreamCliSrt::SrtReceiver::Stop(void)" (?Stop#SrtReceiver#HeliosMediaStreamCliSrt##$$FQE$AAMXXZ)
Sample:
// pch.h
#ifndef PCH_H
#define PCH_H
#include <srt.h>
#include <stdio.h>
#include <tchar.h>
#include <memory>
#include <map>
#include <stdlib.h>
#endif //PCH_H
// SrtReceiver.h
#pragma once
using namespace System;
namespace TestSrt {
public ref class SrtReceiver {
public:
void SrtReceiver::Stop();
private:
};
}
// SrtReceiver.cpp
#include "pch.h"
#include "SrtReceiver.h"
namespace TestSrt {
void SrtReceiver::Stop() {
srt_cleanup();
}
}
Project Configuration:
General -> Configuration Type: Dynamic Library (.dll)
Advanced -> Common Language Runtime Support: .NET Core Runtime Support (/clr:netcore)
Advanced -> .NET Core Target Framework: .NET 5.0
C/C++ -> General -> Common Language Runtime Support: NetCore
I'm pretty rusty with C++ so I'm unfamiliar with the build system and its resulting in confusing errors. I've never tried doing anything with .net core in c++ before as C# is more my speed. This looks like something to do with build properties and the compiler is looking for the wrong internal method names. How would I go about fixing this?
I simply forgot to include the paths to the .lib files in Linker -> Input -> Additional Dependencies: /path/to/srt.lib
Simple, but spent hours of google searching to no avail. Hopefully this helps out other a C++ beginners as I didn't come across it.

Created an empty project in visual studio and it doesn't seem to open console anymore?

I was having errors with a project that I created using the console application template and decide to re-create the project with an empty template. This seems to have dealt with the "unresolved external symbol" error I was receiving but now the console won't open when I call cout for output.
#include<iostream>
#include<string>
#include <fstream>
#include <vector>
#include "pch.h"
#include "word.h"
#include "dictionary.h"
using namespace std;
int main()
{
Dictionary dic;
dic.loadDictionary();
cout >> "Hey\n" >> endl;
cout.flush();
}
There are two class files that are being used but as there are no error I don;t believe they are needed to be seen.
Thanks for any help!
EDIT: The original project that was receiving errors were "LNK2019 unresolved external symbol "public: void __thiscall Dictionary::loadDictionary(void)" (?loadDictionary#Dictionary##QAEXXZ) referenced in function _main ConsoleApplicationASS"
Use << instead of >>. Also put getch() at the end for the console to wait for your input so that you can see the console output.
After edit on the question, you should read about solving the LNK2019.
Maybe it is showing up, and closing before you see any output. Try Ctrl+F5. That makes you input a keystroke at the end of execution similar to the getch() command.

How to access my code using Visual Studio CppUnitTestFramework

I wish to unit test my code. It is a proprietary step in a task I have, the code of which I already wrote.
I am using VS Community 2017 v.15.9.7. I have followed the instructions of this site to the utmost detail, line by line:
https://blogs.msdn.microsoft.com/vcblog/2017/04/19/cpp-testing-in-visual-studio/#Setup
But after all the includes I get two errors :
1) Error LNK1120 1 unresolved externals UnitTest1 \source\repos\Primes\Debug\UnitTest1.dll 1
2) Error LNK2019 unresolved external symbol "public: bool __thiscall SearchPrimes::IsPrime(int)" (?IsPrime#SearchPrimes##QAE_NH#Z) referenced in function "public: void __thiscall UnitTest1::TestClass::IsOdd(void)" (?IsOdd#TestClass#UnitTest1##QAEXXZ) UnitTest1 C:\Users\Velzevoul\source\repos\Primes\UnitTest1\unittest1.obj
I have tried moving files, but I thing randomly moving them around will do more harm than good. I read about including the "stdafx.h" to my "source", but that made thing worse, as more errors kept popping up.
Here are the header files of the code I wrote:
#pragma once
#include <vector>
#include "XMLParser.h"
class SearchPrimes
{
public:
std::vector<int> RangePrime(const std::pair<int, int>&);
//Setting the range to search for prime numbers, executing the algorithm
bool IsPrime(int); //The algorithm that checks if a number is prime
bool IsOdd(int); //Checking if a number if even or odd
};
#pragma once
#include <iostream>
#include <vector>
class XMLParser
{
public:
void removeTags(std::string&); //Removing the brackets of the tags of the .xml
std::string openFile(std::string); //Opening a file
std::vector<std::string> readFile(const std::string&, std::string);
//Getting the text from the .xml file to a vector
std::vector<std::pair<int, int> > stringsToInts();
//Finding the values of the tags that contain the ranges
//and converting the string numbers to a vector<int>
};
Here is the test.cpp
#include "stdafx.h"
#include "CppUnitTest.h"
#include "/Users/Velzevoul/source/repos/Primes/Primes/SearchPrimes.h"
#include "/Users/Velzevoul/source/repos/Primes/Primes/XMLParser.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest1
{
TEST_CLASS(TestClass)
{
public:
TEST_METHOD(IsOdd)
{
SearchPrimes prime;
Assert::IsTrue(prime.IsPrime(4));
}
};
}
What do I have to do in order to solve the external dependencies? The article says, that once I follow the steps I can begin. The test is in a separate project, as the article suggests. If you think that the problem may be related to my main() function, please tell me to include it. I do not right now, because it's quite lengthy.
I thank you for your time in advance!
That article is suggesting that you can just link to a Windows executable the same way you would a DLL. I suppose this is theoretically be possible if your executable has been set up to export its functions, but it seems like an odd thing to do.
There are two options for accessing the code under test in a C++ unit test project:
Add the source modules (.cpp/.h) to your unit test project.
Link with a library containing the code.
If your project is relatively simple, with just a few .cpp modules, then option 1 is probably the way to go. Right-click your unit test project, select "Add -> Existing Item..." and add the .cpp modules you want to test.
For a more complex project with many source modules, option 2 might be a better option. Create one or more library projects (static or dynamic) to contain your source modules, then link both the executable and unit test projects with the library.
A good practice is to create one unit test project for each project to be tested. Give the unit test project a name that indicates what project it is testing, i.e. MyExecutable and MyExecutable.Test, MyLibrary and MyLibrary.Test, etc.

Qr read and generation under QT creator using leadtools

I want to buy license for QR codes read and generating from Leadtools but first I want to try their demo tools. I'm using MSVC 2013 x64 compiler. I think I did everything as follows in documentation:
Copied all dll's to my project directory (where build and release folder are located)
Copied Include and Lib folders to my project directory and add this lines to .pro file.
LIBS += -L$$PWD/Lib/CDLLVC12/x64/ -lLtkrn_x
INCLUDEPATH += $$PWD/Include
PRE_TARGETDEPS += $$PWD/Bin/CDLLVC12/x64/Ltkrnx.dll
include and #define LTV19_CONFIG, here is my code:
#define LTV19_CONFIG
#include <iostream>
#include <Ltkrn.h>
#include <ClassLib/LtWrappr.h>
using namespace std;
int main( ){
if( LT_KRN == LBase::LoadLibraries( LT_KRN, LT_DLGKRN))
cout << "success" << endl;
L_TCHAR licenseFile[] = L"d:\\temp\\TestLic.lic";
L_TCHAR key[] = L"xyz123abc";
LSettings::SetLicenseFile( licenseFile, key);
return 0;
}
Ask leadtools support, but they don't have much experience with working with QT...
When I tries to build application I get following errors:
LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl LBase::LoadLibraries(unsigned int,unsigned int)" (__imp_?LoadLibraries#LBase##SAIII#Z) referenced in function main
LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl LSettings::SetLicenseFile(wchar_t *,wchar_t *)" (__imp_?SetLicenseFile#LSettings##SAHPEA_W0#Z) referenced in function main
For following methods documentation says that I only need one dll/lib package (ltkrn). How to fix it? Still I don't get differences between static and dynamic linkage and this could be the problem.
If your linker accepted the 64-bit Ltkrn_x.lib, this suggests the problem is related to how you're using LEADTOOLS and not to QT. That's why I'm posting this as suggested reply instead of a note.
When programming using LEADTOOLS with C++, you normally use one of 2 sets of headers and LIBs:
Either include L_Bitmap.H (or a bunch of headers that includes LtKrn.H) and use the Ltkrn_x, Ltfil_x, etc. set of LIB files.
Or include ClassLib\LtWrappr.h and use only one LIB file, which in your case is Ltwvc_x.lib
Although in both cases you would be using many of the same DLL files such as Ltfilx.dll and Ltkrnx.dll, the reason you don't need their LIB files when using LtWrapper is that the ClassLibrary performs late (on demand) loading of these DLLs at run-time instead of referencing their LIB files at link time.
That's also why you need to call LBase::LoadLibraries() and specify the DLLs you need before your code uses these DLLs.
So to summarize, please try this:
Remove #include "Ltkrn.h"
Remove the linker reference to Ltkrn_x.lib (although you'll need the DLL)
Keep #include "ClassLib/LtWrappr.h"
Add a linker reference to Ltwvc_x.lib

OPENCV linking Error - Win32 & VS2012

i have build openCV 3.0.0 both alpha & beta versions. but everytime i run my project i get this Error only for "imread" function:
error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread#cv##YA?AVMat#1#ABVString#1#H#Z) referenced in function _main ...
Here's my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
int main()
{
Mat a=Mat::zeros(10,10,0);
Mat b;
b=imread("Mu.jpg");
imshow("s",a);
waitKey(1000);
}
when i remove the "imread" function it works fine. builds and runs with no errors and displays the little black image (from "A" Matrix)
I have Re-Build the solutions & OpenCV from scratch and still getting this error.
I'm working with VS2012 and i have added the include & lib paths in a property sheet for the project.
Can anyone help with this?
imread function has been moved to imgcodecs library so you have to include it :
For MSVC users : add "opencv_imgcodecs300d.lib" to "configuration properties-> Linker->Input->Aditional Dependencies" and include "#include "
For Qt users : For Qt IDE users add -lopencv_imgcodecs300d or -lopencv_imgcodecs300 to your .pro file
and #include <opencv2/imgcodecs/imgcodecs.hpp> to your main file
note: the number 300 in the lib name should be changed to match OpenCV version used.
This unresolved external symbol linker errors basically arrives when the compiler is not able to get the definition of that function which is declared.
So make sure you have defined imread("Mu.jpg"){} somewhere in your code and then try compiling the same.
Check whether you have linked the libraries properly and also link may be useful if you are using opencv2.2.