grt
grt copied to clipboard
LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::VectorFloat::~VectorFloat(void)" (__imp_??1VectorFloat@GRT@@UAE@XZ) referenced in function "public: __thiscall GRT::GaussNeuron::~GaussNeuron(void)" (??1GaussNeuron@GRT@@QAE@XZ)
After I received lots of deprecated method errors for save and load which I followed the error suggestions and they got resolved as well as one for
Severity Code Description Project File Line Category Source Suppression State Tool
Error C4996 'GRT::ClassificationData::partition': partition(...) is deprecated, use split(...) instead
I get this new error. Am I using it wrong? Or what's wrong in general? I did a git clone of the repo
cd build
mkdir tmp
cd tmp
cmake ..
build
and then am pointing to GRT folder in my ml101.cpp file as in below.
Severity Code Description Project File Line Category Source Suppression State Tool
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::VectorFloat::~VectorFloat(void)" (__imp_??1VectorFloat@GRT@@UAE@XZ) referenced in function "public: __thiscall GRT::GaussNeuron::~GaussNeuron(void)" (??1GaussNeuron@GRT@@QAE@XZ) mloneohone c:\Users\mona6\documents\visual studio 2015\Projects\mloneohone\mloneohone\ml101.obj 1 Build
#include "E:\opensource_codes\gesture_recognition\grt\GRT\GRT.h"
using namespace GRT;
int main(int argc, const char * argv[])
{
//We are going to use the Iris dataset, you can find more about the orginal dataset at: http://en.wikipedia.org/wiki/Iris_flower_data_set
//Create a new instance of LabelledClassificationData to hold the training data
LabelledClassificationData trainingData;
//Load the training dataset from a file, the file should be in the same directory as this program
if (!trainingData.loadDatasetFromFile("IrisData.txt")) {
std::cout << "Failed to load Iris data from file!\n";
return EXIT_FAILURE;
}
//Print some basic stats about the dataset we have loaded
trainingData.printStats();
//Partition the training dataset into a training dataset and test dataset
//We will use 60% of the data to train the algorithm and 40% of the data to test it
//The true parameter flags that we want to use stratified sampling, which means there
//should be an equal class distribution between the training and test datasets
//LabelledClassificationData testData = trainingData.partition(60, true);
LabelledClassificationData testData = trainingData.split(60, true);
//Setup the gesture recognition pipeline
GestureRecognitionPipeline pipeline;
//Add a KNN classification algorithm as the main classifier with a K value of 10
pipeline.setClassifier(KNN(10));
//Train the KNN algorithm using the training dataset
if (!pipeline.train(trainingData)) {
std::cout << "Failed to train the pipeline!\n";
return EXIT_FAILURE;
}
//Test the KNN model using the test dataset
if (!pipeline.test(testData)) {
std::cout << "Failed to test the pipeline!\n";
return EXIT_FAILURE;
}
//Print some metrics about how successful the classification was
//Print the accuracy
std::cout << "The classification accuracy was: " << pipeline.getTestAccuracy() << "%\n" << std::endl;
//Print the precision for each class
for (UINT k = 0; k<pipeline.getNumClassesInModel(); k++) {
UINT classLabel = pipeline.getClassLabels()[k];
double classPrecision = pipeline.getTestPrecision(classLabel);
std::cout << "The precision for class " << classLabel << " was " << classPrecision << std::endl;
}
std::cout << std::endl;
//Print the recall for each class
for (UINT k = 0; k<pipeline.getNumClassesInModel(); k++) {
UINT classLabel = pipeline.getClassLabels()[k];
double classRecall = pipeline.getTestRecall(classLabel);
std::cout << "The recall for class " << classLabel << " was " << classRecall << std::endl;
}
std::cout << std::endl;
//Print the confusion matrix
Matrix< double > confusionMatrix = pipeline.getTestConfusionMatrix();
std::cout << "Confusion Matrix: \n";
for (UINT i = 0; i<confusionMatrix.getNumRows(); i++) {
for (UINT j = 0; j<confusionMatrix.getNumCols(); j++) {
std::cout << confusionMatrix[i][j] << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
I found this code sample online. Please point out what's the fix.
The code above looks like an old version, it's using several old APIs, hence the deprecated warnings, however these older APIs should still be supported, so I'm not sure why you are getting the vector float error.
You can find an updated version of this example here:
https://github.com/nickgillian/grt#getting-started-example
Can you point me to where you found this older example so I can update it.
Thanks!
Hey @nickgillian the example you link to above contains an error, testAccuracy is undefined.
But in any case, I can also reproduce the unresolved external symbol issue. Steps to reproduce:
- Create a static build or GRT using the cmake build system + Visual Studio 2015 on Windows 10
- Create a new VS solution using the "getting started" solution that links to grt.lib
- Build
The following errors are generated:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall GRT::VectorFloat::VectorFloat(class GRT::VectorFloat const &)" (__imp_??0VectorFloat@GRT@@QAE@ABV01@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::VectorFloat::~VectorFloat(void)" (__imp_??1VectorFloat@GRT@@UAE@XZ) referenced in function "public: __thiscall GRT::GaussNeuron::~GaussNeuron(void)" (??1GaussNeuron@GRT@@QAE@XZ) ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: double * __thiscall GRT::Matrix<double>::operator[](unsigned int)" (__imp_??A?$Matrix@N@GRT@@QAEPANI@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall GRT::Matrix<double>::getNumRows(void)const " (__imp_?getNumRows@?$Matrix@N@GRT@@QBEIXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall GRT::Matrix<double>::getNumCols(void)const " (__imp_?getNumCols@?$Matrix@N@GRT@@QBEIXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::MatrixFloat::~MatrixFloat(void)" (__imp_??1MatrixFloat@GRT@@UAE@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall GRT::ClassificationSample::getClassLabel(void)const " (__imp_?getClassLabel@ClassificationSample@GRT@@QBEIXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class GRT::VectorFloat & __thiscall GRT::ClassificationSample::getSample(void)" (__imp_?getSample@ClassificationSample@GRT@@QAEAAVVectorFloat@2@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall GRT::ClassificationData::ClassificationData(unsigned int,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> >)" (__imp_??0ClassificationData@GRT@@QAE@IV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall GRT::ClassificationData::ClassificationData(class GRT::ClassificationData const &)" (__imp_??0ClassificationData@GRT@@QAE@ABV01@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::ClassificationData::~ClassificationData(void)" (__imp_??1ClassificationData@GRT@@UAE@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class GRT::ClassificationSample & __thiscall GRT::ClassificationData::operator[](unsigned int const &)" (__imp_??AClassificationData@GRT@@QAEAAVClassificationSample@1@ABI@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __thiscall GRT::ClassificationData::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?load@ClassificationData@GRT@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __thiscall GRT::ClassificationData::printStats(void)const " (__imp_?printStats@ClassificationData@GRT@@QBE_NXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class GRT::ClassificationData __thiscall GRT::ClassificationData::split(unsigned int,bool)" (__imp_?split@ClassificationData@GRT@@QAE?AV12@I_N@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall GRT::ClassificationData::getNumSamples(void)const " (__imp_?getNumSamples@ClassificationData@GRT@@QBEIXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall GRT::GestureRecognitionPipeline::GestureRecognitionPipeline(void)" (__imp_??0GestureRecognitionPipeline@GRT@@QAE@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::GestureRecognitionPipeline::~GestureRecognitionPipeline(void)" (__imp_??1GestureRecognitionPipeline@GRT@@UAE@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class GRT::GestureRecognitionPipeline & __thiscall GRT::GestureRecognitionPipeline::operator<<(class GRT::Classifier const &)" (__imp_??6GestureRecognitionPipeline@GRT@@QAEAAV01@ABVClassifier@1@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall GRT::GestureRecognitionPipeline::test(class GRT::ClassificationData const &)" (__imp_?test@GestureRecognitionPipeline@GRT@@UAE_NABVClassificationData@2@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall GRT::GestureRecognitionPipeline::save(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (__imp_?save@GestureRecognitionPipeline@GRT@@UBE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall GRT::GestureRecognitionPipeline::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?load@GestureRecognitionPipeline@GRT@@UAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall GRT::GestureRecognitionPipeline::getNumClassesInModel(void)const " (__imp_?getNumClassesInModel@GestureRecognitionPipeline@GRT@@QBEIXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall GRT::GestureRecognitionPipeline::getPredictedClassLabel(void)const " (__imp_?getPredictedClassLabel@GestureRecognitionPipeline@GRT@@QBEIXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: double __thiscall GRT::GestureRecognitionPipeline::getTestAccuracy(void)const " (__imp_?getTestAccuracy@GestureRecognitionPipeline@GRT@@QBENXZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: double __thiscall GRT::GestureRecognitionPipeline::getTestFMeasure(unsigned int)const " (__imp_?getTestFMeasure@GestureRecognitionPipeline@GRT@@QBENI@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: double __thiscall GRT::GestureRecognitionPipeline::getTestPrecision(unsigned int)const " (__imp_?getTestPrecision@GestureRecognitionPipeline@GRT@@QBENI@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: double __thiscall GRT::GestureRecognitionPipeline::getTestRecall(unsigned int)const " (__imp_?getTestRecall@GestureRecognitionPipeline@GRT@@QBENI@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class GRT::MatrixFloat __thiscall GRT::GestureRecognitionPipeline::getTestConfusionMatrix(void)const " (__imp_?getTestConfusionMatrix@GestureRecognitionPipeline@GRT@@QBE?AVMatrixFloat@2@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class GRT::Vector<unsigned int> __thiscall GRT::GestureRecognitionPipeline::getClassLabels(void)const " (__imp_?getClassLabels@GestureRecognitionPipeline@GRT@@QBE?AV?$Vector@I@2@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall GRT::ANBC::ANBC(bool,bool,double)" (__imp_??0ANBC@GRT@@QAE@_N0N@Z) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual __thiscall GRT::ANBC::~ANBC(void)" (__imp_??1ANBC@GRT@@UAE@XZ) referenced in function _main ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\ConsoleApplication1.obj 1
Error LNK1120 32 unresolved externals ConsoleApplication1 C:\Users\Jamie Bullock\Documents\ml-lib\build\win32\ConsoleApplication1\Debug\ConsoleApplication1.exe 1
This issue only applies to static linkage. Linking dynamically to grt seems to work fine.
OK, I think I've figured out what's going on here.
For building a static lib, or directly including the GRT sources in a project GRT_STATIC_LIB needs to be defined so that GRT_API is not defined for dll exports. See:
#if !defined(GRT_STATIC_LIB) && defined(_MSC_VER)
#undef GRT_API
#ifdef GRT_DLL_EXPORTS
#define GRT_API __declspec(dllexport)
#else // GRT_DLL_EXPORTS
#define GRT_API __declspec(dllimport)
#endif // GRT_DLL_EXPORTS
//disable warnings about a "dllexport" class using a regular class
# pragma warning(disable: 4251)
#endif // !GRT_STATIC_LIB && MSC_VER
The above problem occurs when GRT_STATIC_LIB is defined for GRT itself, but not for client code that consumes GRT.
The solution is to make sure GRT_STATIC_LIB is defined in the client code preprocessor if it is also defined for the GRT build being used.
@jamiebullock Can you elaborate on what you did to get the static build working? I'm trying to do the same but can't figure out exactly where in the out-of-the-box build process to make changes.
@morphogencc Sorry for the disturbance, but were you able to get the build working? I am facing the same problem.
Unfortunately I haven't gotten it working, though I haven't tried since last year...
@MPillai1 what platform(s) are you on?
I am using Visual Studio 2019 on Windows 10.