I am looking to use the C++ neural network library "OpenNN".
http://www.opennn.net/
I am relatively new to C++ project management and I believe my issue is caused by this.
I have cloned the openNN repo.
I copied the relevant folders form the repo across in to the folder that i created to contain all OpenNN project i plan to make.
I then made a c++ console application in visual studio, in this folder that i am using for testing.
so dir structure is :
OpenNN (where i plan to keep all openNN projects)
---eigen
---opennn
---tinyxml2
---OpenNNTest (my test project folder)
I have done some testing with the Vector and Matrix classes that are part of OpenNN and that all worked fine.
The below code however returns the following two external symbol errors:
Error LNK2019 unresolved external symbol "public: __thiscall OpenNN::NeuralNetwork::NeuralNetwork(class OpenNN::Vector<unsigned int> const &)" (??0NeuralNetwork#OpenNN##QAE#ABV?$Vector#I#1##Z) referenced in function "void __cdecl NNTest(void)" (?NNTest##YAXXZ) OpenNNTest D:\Projects\OpenNN\OpenNNTest\OpenNNTest\OpenNNTest.obj 1
Error LNK2019 unresolved external symbol "public: virtual __thiscall
OpenNN::NeuralNetwork::~NeuralNetwork(void)" (??1NeuralNetwork#OpenNN##UAE#XZ) referenced in function "void __cdecl NNTest(void)" (?NNTest##YAXXZ) OpenNNTest D:\Projects\OpenNN\OpenNNTest\OpenNNTest\OpenNNTest.obj 1
interestingly, if I change:
OpenNN::NeuralNetwork nn(architecture);
to
OpenNN::NeuralNetwork nn();
No issues, as if it finds the default constructor but not the overloaded one?
The code I am using is as follows:
#include "stdafx.h"
#include "../../opennn/opennn.h"
using namespace OpenNN;
using std::cout;
using std::endl;
void NNTest()
{
OpenNN::Vector<unsigned> architecture(5);
architecture[0] = 2;
architecture[1] = 2;
architecture[2] = 4;
architecture[3] = 3;
architecture[4] = 1;
OpenNN::NeuralNetwork nn(architecture);
//Vector<double> inputs(2);
//inputs[0] = 0.5;
//inputs[1] = 0.1;
//Vector<double> outputs = nn.calculate_outputs(inputs);
//cout << outputs << endl;
//nn.save("neural_network.xml");
}
int main()
{
NNTest();
getchar();
return 0;
}
You need to change the type unsigned to size_t:
OpenNN::Vector<size_t> architecture(5);
architecture[0] = 2;
architecture[1] = 2;
architecture[2] = 4;
architecture[3] = 3;
architecture[4] = 1;
OpenNN::NeuralNetwork nn(architecture);
I hope that helps.
Related
I was trying to draw the HalfEdge Data Structure solid with openGL, and I have to subdivision face which may have holes and turn the face to triangles. I use the poly2tri lib. Relate Code is blow.
void Renderer::Poly2Triangles(Face* face)
{
Plane2D plane(face);
std::vector<p2t::Point*> all_points;
std::vector<p2t::Point*> out_points;
std::vector<p2t::Point*> in_points;
//outter loop
Loop* outerLoop = face->fLoops;
while (outerLoop->IsInnerLoop) outerLoop = outerLoop->lNext;
glm::vec3 firstEdge = (outerLoop->lHEdge->destination->Pos).position - (outerLoop->lHEdge->origin->Pos).position;
glm::vec3 secondEdge = (outerLoop->lHEdge->Next->destination->Pos).position - (outerLoop->lHEdge->Next->origin->Pos).position;
glm::vec3 norm = glm::normalize(glm::cross(firstEdge, secondEdge));
HalfEdge* he = outerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
all_points.push_back(point);
out_points.push_back(point);
he = he->Next;
} while (he != outerLoop->lHEdge);
p2t::CDT cdt(std::move(out_points)); //-----------first link error here---------------
//inner loop
Loop* innerLoop = face->fLoops;
do {
if (!(innerLoop->IsInnerLoop)) {
innerLoop = innerLoop->lNext;
continue;
}
HalfEdge* he = innerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
in_points.push_back(point);
all_points.push_back(point);
he = he->Next;
} while (he != innerLoop->lHEdge);
cdt.AddHole(std::move(in_points));//----------------link error-------------
innerLoop = innerLoop->lNext;
} while (innerLoop != face->fLoops);
cdt.Triangulate();//-----------------------link error------------------------
auto tris = cdt.GetTriangles();//------------------------link error----------------------
for (auto tri : tris) {
Triangle triangle;
for (int i = 0; i < 3; i++) {
auto _p = tri->GetPoint(i);
triangle.vertex[i] = plane.Plane2DToSpace3D(glm::vec2(_p->x, _p->y));
triangle.normal[i] = norm;
}
triangles.push_back(triangle);
}
for (auto p : all_points)
delete p;
}
When I try to run it, it shows five link error:
Renderer.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall p2t::CDT::CDT(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)" (??0CDT#p2t##QAE#V?$vector#PAUPoint#p2t##V?$allocator#PAUPoint#p2t###std###std###Z),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall p2t::CDT::~CDT(void)" (??1CDT#p2t##QAE#XZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall p2t::CDT::AddHole(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)" (?AddHole#CDT#p2t##QAEXV?$vector#PAUPoint#p2t##V?$allocator#PAUPoint#p2t###std###std###Z),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall p2t::CDT::Triangulate(void)" (?Triangulate#CDT#p2t##QAEXXZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: class std::vector<class p2t::Triangle *,class std::allocator<class p2t::Triangle *> > __thiscall p2t::CDT::GetTriangles(void)" (?GetTriangles#CDT#p2t##QAE?AV?$vector#PAVTriangle#p2t##V?$allocator#PAVTriangle#p2t###std###std##XZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
just all the p2t::CDT class member was unresolved external symbol: CDT、~CDT、CDT::AddHole、 CDT::Triangulate、CDT::GetTriangles
I use VS2022 build this project, I add the poly2tri header file to the include file path in project properties. the file structure is blow and I just #include "poly2tri.h". it actually pass the compile.
I have no idea what's going on, I want to find errors and correct them. Or I'm happy to know other way to subdivision polygon to triangles.
just like the headline says.. i got this piece of code
std::string dir;
(ls == 1) ? dir = "Long" : dir = "Short";
which generates error i don´t understand
LNK2019: unresolved external symbol _CrtDbgReportW referenced in function
"void * __cdecl std::_Allocate(unsigned __int64,unsigned __int64,bool)
when i switch to
const char* dir;
(ls == 1) ? dir = "Long" : dir = "Short";
all works pretty fine.
what is the deal there?
In
std::string dir;
(ls == 1) ? dir = "Long" : dir = "Short";
dir is a std::string, a fairly complex class that will be pulling in bits and pieces from all over the standard library, including memory allocation which appears to be calling a Windows debug helper function, _CrtDbgReportW, under some circumstances. For whatever reason, this debug helper function is not being linked.
But in
const char* dir;
(ls == 1) ? dir = "Long" : dir = "Short";
dir is just a simple pointer, an address. dir = "Long" simply points dir at the string literal "long". This is just a simple assignment that requires no help from any libraries.
I am a noobie with C++. My first learning project uses GoogleTest and GoolgleMock, but, of course, I am new to those also. I installed googletestmock.v.141 v101 via NuGet. My main app, AstronomyCalculations, builds and runs without a problem. My test app, GMock, throws three LNK2019 errors when I try to build it.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __cdecl easter::easter(void)" (??0easter##QEAA#XZ) referenced in function "private: virtual void __cdecl GET_THE_DATE_OF_EASTER_ShouldReturnDateOfEaster_Test::TestBody(void)" (?TestBody#GET_THE_DATE_OF_EASTER_ShouldReturnDateOfEaster_Test##EEAAXXZ) GMock D:\Dev\Projects\AstronomyCalculations\GMock\GMock.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __cdecl easter::~easter(void)" (??1easter##QEAA#XZ) referenced in function "private: virtual void __cdecl GET_THE_DATE_OF_EASTER_ShouldReturnDateOfEaster_Test::TestBody(void)" (?TestBody#GET_THE_DATE_OF_EASTER_ShouldReturnDateOfEaster_Test##EEAAXXZ) GMock D:\Dev\Projects\AstronomyCalculations\GMock\GMock.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: struct tm __cdecl easter::get_easter_date(int)const " (?get_easter_date#easter##QEBA?AUtm##H#Z) referenced in function "private: virtual void __cdecl GET_THE_DATE_OF_EASTER_ShouldReturnDateOfEaster_Test::TestBody(void)" (?TestBody#GET_THE_DATE_OF_EASTER_ShouldReturnDateOfEaster_Test##EEAAXXZ) GMock D:\Dev\Projects\AstronomyCalculations\GMock\GMock.obj 1
// AstronomyCalculations.cpp
int main() {
return 0;
}
// Easter.h
#pragma once
#include <ctime>
#include <string>
class easter
{
public:
easter();
~easter();
tm get_easter_date(int easter_year) const;
};
// Easter.cpp
#include "Easter.h"
easter::easter()
{
}
easter::~easter()
= default;
tm easter::get_easter_date(const int easter_year) const
{
const auto a = easter_year % 19;
const auto b = easter_year / 100;
const auto c = easter_year % 100;
const auto d = b / 4;
const auto e = b % 4;
const auto f = (b + 8) / 25;
const auto g = (b - f + 1) / 3;
const auto h = ((19 * a) + b - d - g + 15) % 30;
const auto i = c / 4;
const auto k = c % 4;
const auto l = (32 + (2 * e) + (2 * i) - h - k) % 7;
const auto m = (a + (11 * h) + (22 * l)) / 451;
const auto easter_month = (h + l - (7 * m) + 114) / 31;
const auto easter_day = ((h + l - (7 * m) + 114) % 31) + 1;
auto date_string = std::to_string(easter_year) +
"-" +
std::to_string(easter_month) +
"-" +
std::to_string(easter_day) +
" 00:00:00";
char date[20]; //a 1 char space for null is also required
strcpy_s(date, date_string.c_str());
tm ltm{};
char seps[] = " -:";
char *next_token = nullptr;
auto token = strtok_s(date, seps, &next_token);
ltm.tm_year = strtol(token, nullptr, 10);
token = strtok_s(nullptr, seps, &next_token);
ltm.tm_mon = strtol(token, nullptr, 10);
token = strtok_s(nullptr, seps, &next_token);
ltm.tm_mday = strtol(token, nullptr, 10);
token = strtok_s(nullptr, seps, &next_token);
ltm.tm_hour = strtol(token, nullptr, 10);
token = strtok_s(nullptr, seps, &next_token);
ltm.tm_min = strtol(token, nullptr, 10);
token = strtok_s(nullptr, seps, &next_token);
ltm.tm_sec = strtol(token, nullptr, 10);
ltm.tm_wday = 0;
return ltm;
}
// GMock.cpp
#include "stdafx.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "Easter.h"
int main(int argc, char** argv)
{
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
TEST(GET_THE_DATE_OF_EASTER, ShouldReturnDateOfEaster)
{
easter estr;
const auto result = estr.get_easter_date(2000);
ASSERT_EQ(result.tm_year, 2000);
}
The linker seems unable to find the functions easter::easter(void), easter::~easter(void), and easter::get_easter_date(int)const
You are obviously including easter.h (and have it in your search path, or the compiler would have complained) but are you actually compiling easter.cpp or a mock object of it? (As far as I can tell from your sourcecode you are not actually mocking the class either). The header file is enough to satisfy the compiler, but when the linker tries to put the application together and realizes it is missing the object file, it balks - throwing LNK2019.
I can only strongly reccommend you look deeper into the documentation available for gtest & gmock.
In addition, you may also reconsider your naming schemes - Class types usually begin with an uppercase (i.e. Easter, not easter) to better tell them from variable names (which begin with lowercase). Also don't call your variables a, b, c, d - const auto a and its ilk are horrible to read, debug, and you will curse yourself I you ever find yourself in the postion of having to revisit the code after some weeks. Even if this were only some practice project, please also practice using good coding standards & naming conventions, so you (automatically) use them on bigger projects.
I finally solved this when I discovered that GoogleTest can be added in Visual Studio 2017 as a new project. Of course, I had to remove my original test project first and then add the new test project. It all worked out in the end, but, of course, I have no idea of why the link errors showed up in my original testing project; other than CharonX's insights.
So I am using TagLib in WinRT Component and trying to get Album arts of mp3 files and then save them to separate files. So far I am using this code:
auto albumartFolder = ApplicationData::Current->LocalFolder;
StorageFile^ destStorageFile = create_task(albumartFolder->CreateFileAsync("\\AlbumArts\\" + destFileName + ".jpg")).get();
TagLib::MPEG::File mpegFile(file->Path->Data());
static const char *IdPicture = "APIC";
TagLib::ID3v2::Tag *id3v2tag = mpegFile.ID3v2Tag();
TagLib::ID3v2::FrameList Frame;
TagLib::ID3v2::AttachedPictureFrame *PicFrame;
void *RetImage = NULL, *SrcImage;
unsigned long Size;
FILE *jpegFile;
jpegFile = fopen((char*)destStorageFile->Path->Data(), "wb");
if (id3v2tag)
{
Frame = id3v2tag->frameListMap()[IdPicture];
if (!Frame.isEmpty())
{
for (TagLib::ID3v2::FrameList::ConstIterator it = Frame.begin(); it != Frame.end(); ++it)
{
PicFrame = (TagLib::ID3v2::AttachedPictureFrame *)(*it);
if ( PicFrame->type() ==
TagLib::ID3v2::AttachedPictureFrame::FrontCover)
{
Size = PicFrame->picture().size();
SrcImage = malloc(Size);
if (SrcImage)
{
memcpy(SrcImage, PicFrame->picture().data(), Size);
fwrite(SrcImage, Size, 1, jpegFile);
fclose(jpegFile);
free(SrcImage);
}
}
}
}
}
This code should work without a bug I know but here are the exceptions I am recieving:
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: __thiscall TagLib::FileName::FileName(wchar_t const *)" (??0FileName#TagLib##QAE#PB_W#Z) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: __thiscall TagLib::MPEG::File::File(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (??0File#MPEG#TagLib##QAE#VFileName#2#_NW4ReadStyle#AudioProperties#2##Z) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall TagLib::MPEG::File::~File(void)" (??1File#MPEG#TagLib##UAE#XZ) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
Any help regarding this would be appreciated very much!
Edit:
So, this is marked as duplicate but I still cannot fix the problem. How do I link Taglib correctly? I installed the Nuget package, was I wrong to do so?
I'm using C++ and Visual Studio Professional 2013 to write a wrapper for the Windows API (to make it easier to read). When I try to compile the solution, I get two linker errors related to the Intersect function in the wRectangle class. I commented out the function to see what the cause of the problem was, and the solution compiled and ran fine. From this, I determined that it was because the return type was an object of the class name (i.e. The Intersect function in the wRectangle class returns a wRectangle object). Moving the implementation of the Intersect function to its prototype in Rectangle.h fixed the issue, but I would prefer to keep the implementation in Rectangle.cpp. Any way to solve this?
Relevant files, most of the comments have been removed since they serve no relevance:
Rectangle.h:
#include <Windows.h>
#include "Typedefs.h"
#include "Window.h"
namespace windows_API_Wrapper
{
#ifndef RECTANGLE_H
#define RECTANGLE_H
class wRectangle
{
public:
wRectangle();
wRectangle(uInt32 xMin, uInt32 xMax, uInt32 yMin, uInt32 yMax);
void operator=(wRectangle &assignment);
void operator=(Window assignment);
boolean operator!=(wRectangle nonComparable);
wRectangle Intersect(wRectangle source1, wRectangle source2);
void Normalize();
private:
rectangle rect; //A wRectangle structure (typedef of a RECT strucure), for internal use only
};
#endif //RECTANGLE_H
}
Rectangle.cpp:
#include "Rectangle.h"
using namespace windows_API_Wrapper;
wRectangle::wRectangle()
{
this->rect.left = 0;
this->rect.top = 0;
this->rect.right = 0;
this->rect.bottom = 0;
}
void wRectangle::operator=(wRectangle &assignment)
{
this->rect.left = assignment.rect.left;
this->rect.top = assignment.rect.top;
this->rect.right = assignment.rect.right;
this->rect.bottom = assignment.rect.bottom;
}
void wRectangle::operator=(Window assignment)
{
if (GetClientRect(assignment.Get(), &this->rect) == 0)
MessageBox(null, "Failed to assign window dimensions to wRectangle!", "ERROR", MB_ICONEXCLAMATION);
}
boolean wRectangle::operator==(wRectangle comparable)
{
return EqualRect(&this->rect, &comparable.rect);
}
boolean wRectangle::operator!=(wRectangle nonComparable)
{
return !EqualRect(&this->rect, &nonComparable.rect);
}
wRectangle wRectangle::Intersect(wRectangle source1, wRectangle source2)
{
wRectangle destination;
IntersectRect(&destination.rect, &source1.rect, &source2.rect);
return destination;
}
void wRectangle::Normalize()
{
if (this->rect.top > this->rect.bottom)
{
uInt32 temp = this->rect.top;
this->rect.top = this->rect.bottom;
this->rect.bottom = temp;
}
if (this->rect.left > this->rect.right)
{
uInt32 temp = this->rect.left;
this->rect.left = this->rect.right;
this->rect.right = temp;
}
}
Error 1:
error LNK2019: unresolved external symbol "public: __thiscall
windows_API_Wrapper::wRectangle::wRectangle(class windows_API_Wrapper::wRectangle const &)" (??
0wRectangle#windows_API_Wrapper##QAE#ABV01##Z) referenced in function "public: class
windows_API_Wrapper::wRectangle __thiscall windows_API_Wrapper::wRectangle::Intersect(class
windows_API_Wrapper::wRectangle,class windows_API_Wrapper::wRectangle)" (?
Intersect#wRectangle#windows_API_Wrapper##QAE?AV12#V12#0#Z)
File: G:\Visual Studio Projects\Windows API Wrapper\Windows API Wrapper\Rectangle.obj
Project: Windows API Wrapper
Error 2:
error LNK1120: 1 unresolved externals
File: G:\Visual Studio Projects\Windows API Wrapper\Debug\Windows API Wrapper.exe
Project: Windows API Wrapper
This is because you have not defined
wRectangle(uInt32 xMin, uInt32 xMax, uInt32 yMin, uInt32 yMax);