VC++ Problems using gumbo-query (linking error) - c++

I've got a VC++ project, and I'm attempting to use the extension of the gumbo-query library, found here. This library wraps/extends Google's gumbo-parser found here. The following is the exact steps I've taken - I'm not very familiar with importing libraries, so I've done what I do to use the Boost libraries:
In Visual Studio (VS Community 2013), under the project settings -> Configuration Properties -> C/C++ -> General I have put the path to a folder that contains all of the source files from both of the projects linked above. Specifically, I placed the .c, .cpp and .h files from the src folder of both projects and referenced these in my projects settings as an include directory.
Following the example file for the project that extends Google's gumbo-parser (found here), I added these two lines to import the library:
#include "Document.h"
#include "Node.h"
At this point, my solution compiles fine. However, continuing to follow the example file, adding the first variable declaration:
CDocument d;
Causes a linker error, as follows:
1>Main.obj : error LNK2028: unresolved token (0A0003B7) "public: __thiscall CDocument::CDocument(void)" (??0CDocument##$$FQAE#XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork#Main#MyApplication##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)
1>Main.obj : error LNK2028: unresolved token (0A0003B8) "public: virtual __thiscall CDocument::~CDocument(void)" (??1CDocument##$$FUAE#XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork#Main#MyApplication##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall CDocument::CDocument(void)" (??0CDocument##$$FQAE#XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork#Main#MyApplication##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)
1>Main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CDocument::~CDocument(void)" (??1CDocument##$$FUAE#XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork#Main#MyApplication##$$FA$AAMXP$AAVObject#System##P$AAVDoWorkEventArgs#ComponentModel#4##Z)
1>..{omitted}..\MyApplication.exe : fatal error LNK1120: 4 unresolved externals
This error appears to occur no matter where I put a CDocument instantiation.
What can I do to rectify this? VS seems to think the includes are fine, and moreso when I put in CDocument d; it lights up to show it recognises the CDocument type.

As always, it's clear I've been a JS developer for too long. I really did need to compile a .lib file. Thank you to Christian for reminding me of this.
The original gumbo-parser project by Google includes a VS project. I opened this and compiled it, fixing all of the project settings problems so that I could import it into my project, which I did via the Configuration Properties -> Linker -> Input -> Additional Dependencies setting for my VS project.
Next, I added the extra source files from the wrapper library gumbo-query, where I had to fix a naming conflict between parser.h/parser.cpp from the original gumbo-parser project and the Parser.h/Parser.cpp file in the wrapper library. I also changed all references to #include <gumbo.h> to #include "gumbo.h"
Eventually, I got a gumbo.lib file containing both the original and the wrapper libraries, and this imported into my project and I now seem to be able to successfully use the functions.

Related

OpenCascade link error in c++ using vs2017

I am a newbie to Open Cascade.After building occt-7.3.0-vc14-64 with cmake with no error, i added inc/ in Include Directories and added win64/vc14/libd/ in Library Directories, then added only "include" in main.cpp. But after clicked debug button, i got link error as following:
Error LNK2019 unresolved external symbol "public: __cdecl
Standard_OutOfMemory::Standard_OutOfMemory(char const * const)" (??
0Standard_OutOfMemory##QEAA#QEBD#Z) referenced in function "public:
void __cdecl Standard_OutOfMemory::`default constructor closure'(void)"
(??_FStandard_OutOfMemory##QEAAXXZ)
What else should have be done?
Thanks for any help.
This error is that can't find lib that contain Standard_OutOfMemory.
Standard_OutOfMemory is a class in TKernel.dll, you should add TKernel.lib to project's Additional Dependencies, like on the image below:

How to use class from a different project in C++ with Qt?

There's this class MailHandler in the solution MailTest, which I use to send signals to the class MailCom in the solution MailResponse. My problem revolves around creating an object of the MailHandler class in the MailCom class, which is in a different project, and doing operations from here. What is the most efficient way of establishing the connection without modifying the MailTest project into a lib or DLL?
I need to link with a correct path, but I'm not sure at which settings are important in this case. This is the current error I'm getting when trying to instantiate the MailHandler object:
1> Creating library ..\..\bin\pvc6d.lib and object ..\..\bin\pvc6d.exp
1>CMailCom.obj : error LNK2019: unresolved external symbol "public: class QStringList __thiscall MailHandler::ReturnAllFunctions(void)" (?ReturnAllFunctions#MailHandler##QAE?AVQStringList##XZ) referenced in function "public: __thiscall pvc::hardwarecom::CMailCom::CMailCom(class pvc::data::CData &,class pvc::data::CRudderServo *,class pvc::data::CPropulsionManager *,class QGraphicsScene *)" (??0CMailCom#hardwarecom#pvc##QAE#AAVCData#data#2#PAVCRudderServo#42#PAVCPropulsionManager#42#PAVQGraphicsScene###Z)
1>CMailCom.obj : error LNK2019: unresolved external symbol "public: __thiscall MailHandler::MailHandler(class QObject *)" (??0MailHandler##QAE#PAVQObject###Z) referenced in function "public: __thiscall pvc::hardwarecom::CMailCom::CMailCom(class pvc::data::CData &,class pvc::data::CRudderServo *,class pvc::data::CPropulsionManager *,class QGraphicsScene *)" (??0CMailCom#hardwarecom#pvc##QAE#AAVCData#data#2#PAVCRudderServo#42#PAVCPropulsionManager#42#PAVQGraphicsScene###Z)
1>..\..\bin\pvc6d.exe : fatal error LNK1120: 2 unresolved externals
If you want to use a class of a external project, you can try to #include its header file (MailHandler.h, MailHandler.hxx etc.). I assume thats what you did. Obviously there is also a according source file (MailHandler.cpp, MailHandler.cxx). You can try to add this file to your current project. If you are lucky it compiles and links and your unresolved externals go away. More likely the source file has other dependencies and does not compile/link right away.
This is rather a hack - not a robust long term solution.
It's better to copy the file with its dependencies into your project
It's best to extract the needed classes in a separate project (i.e creating a lib or dll) that your project and that the other solution 'MailTest' are using as a independent client.
You are missing the correct libraries. The linker does not know about the functions called, add LIBS += -Lpath/to/lib -lthelib to your pro file.

Unresolved externals when compiling unit tests for Visual C++ 2012

I want to create unit tests for a Visual C++ project. I tried following these MSDN instructions. I've found pages where they differentiate between unmanaged/mixed/pure code, but I don't fully understand those concepts. My code doesn't use .NET and would likely compile under MinGW with a few code adjustments.
My main project builds an executable, so I followed the steps under To reference exported functions from the test project. For starters I got different project options:
I went with Native Unit Test Project. I added a reference to my main project and I set Include Directories to $(SolutionDir)\Cubes;$(IncludePath). I wrote my code and got this when compiling:
1>Creating library C:\Users\Pieter\Dropbox\Unief\TTUI\TTUIproject\Cubes\Debug\CubesTest.lib and object C:\Users\Pieter\Dropbox\Unief\TTUI\TTUIproject\Cubes\Debug\CubesTest.exp
1>LayoutTest.obj : error LNK2019: unresolved external symbol "public: __thiscall Room::Room(void)" (??0Room##QAE#XZ) referenced in function "public: void __thiscall CubesTest::LayoutTest::NumOfRoomsConsistency(void)" (?NumOfRoomsConsistency#LayoutTest#CubesTest##QAEXXZ)
1>LayoutTest.obj : error LNK2019: unresolved external symbol "public: __thiscall Layout::Layout(class Room *,int)" (??0Layout##QAE#PAVRoom##H#Z) referenced in function "public: void __thiscall CubesTest::LayoutTest::NumOfRoomsConsistency(void)" (?NumOfRoomsConsistency#LayoutTest#CubesTest##QAEXXZ)
1>LayoutTest.obj : error LNK2019: unresolved external symbol "public: void __thiscall Layout::add(int,int,class Room *)" (?add#Layout##QAEXHHPAVRoom###Z) referenced in function "public: void __thiscall CubesTest::LayoutTest::NumOfRoomsConsistency(void)" (?NumOfRoomsConsistency#LayoutTest#CubesTest##QAEXXZ)
1>LayoutTest.obj : error LNK2019: unresolved external symbol "public: void __thiscall Layout::clear(int,int,bool)" (?clear#Layout##QAEXHH_N#Z) referenced in function __catch$?NumOfRoomsConsistency#LayoutTest#CubesTest##QAEXXZ$0
1>C:\Users\Pieter\Dropbox\Unief\TTUI\TTUIproject\Cubes\Debug\CubesTest.dll : fatal error LNK1120: 4 unresolved externals
If I'm not mistaken, this means that the compiler finds the header files, but not the source files. What am I missing?
Here is a step-by-step description on how to add an EXE as an unit-test target.
The key point is to "export" the functions/classes you want to test... You can download the complete sample here: http://blog.kalmbachnet.de/files/CPP_UnitTestApp.zip (I did not change any project settings, so all changes you can see in the source-code; of course, some parts can be made in the project settings).
Create a Win32 Application (Console or MFC or Windows, does not matter); I created a console project called CPP_UnitTestApp:
Add a function you want to test (you can also add classes). For example:
int Plus1(int i)
{
return i+1;
}
Add a header file for the functions you want to test: CPP_UnitTestApp.h
Put the declaration of the methods into the header file, and also export these functions!
#pragma once
#ifdef EXPORT_TEST_FUNCTIONS
#define MY_CPP_UNITTESTAPP_EXPORT __declspec(dllexport)
#else
#define MY_CPP_UNITTESTAPP_EXPORT
#endif
MY_CPP_UNITTESTAPP_EXPORT int Plus1(int i);
Include this header file in the main-cpp (here CPP_UnitTestApp.cpp) and define the EXPORT_TEST_FUNCTIONS before including the header:
#define EXPORT_TEST_FUNCTIONS
#include "CPP_UnitTestApp.h"
Now add a new project (Native unit test project: UnitTest1)
Include the header and the lib to the "unittest1.cpp" file (adopt the paths as you want):
#include "..\CPP_UnitTestApp.h"
#pragma comment(lib, "../Debug/CPP_UnitTestApp.lib")
Go to the project settings of the test project add add a reference to the "UnitTest1" project (Project|Properties|Common Properties|Add New Reference...: Select under "Projects" the "CPP_UnitTestApp"-Project)
Create the unit test function:
TEST_METHOD(TestMethod1)
{
int res = Plus1(12);
Assert::AreEqual(13, res);
}
Run your unit test ;)
As you can see, the main point was to export the function declaration! This is done via __declspec(dllexport) even if it is an EXE.
As I said, the demo project can be downloaded here: http://blog.kalmbachnet.de/files/CPP_UnitTestApp.zip

Linking with glog library

I'm trying to use the glog logging library (LINK).
In VS2012 (I'm on Windows 8 Professional 64-bit (Japanese)), I create an empty solution with a single main.cpp file like the one in the documentation (LINK).
Also I import the glog project inside the solution (either the dll one or the static library one) and set the project dependency.
To avoid some errors I have to comment out line 97 from port.h:
/* In windows-land, hash<> is called hash_compare<> (from xhash.h) */
#define hash hash_compare
While glog compiles, the main application gives me unresolved external symbol erros (with both dll and static version).
1>main.obj : error LNK2019: 未解決の外部シンボル "void __cdecl google::InitGoogleLogging(char const *)" (?InitGoogleLogging#google##YAXPBD#Z) が関数 _main で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル "public: __thiscall google::LogMessage::LogMessage(char const *,int)" (??0LogMessage#google##QAE#PBDH#Z) が関数 _main で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル "public: __thiscall google::LogMessage::~LogMessage(void)" (??1LogMessage#google##QAE#XZ) が関数 _main で参照されました。
I'm compiling as Win32.
If I check the debug folder it actually contains the dll+lib or static lib file.
I also tried linking to the library manually without using the visual studio dependency system, but it's the same.
I've built glog for MSVS2012 from trunk (little patch mentioned in header already presented here, as i know), so it works for me.
Looks like your dependency description of glog library is missing.
Can you add windows-specific
#pragma comment(lib, "path_to_glog_from_project_dir.lib")
to one of your project files, for example, directly into main.cpp and test it.

Help on jrtplib and jthread

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.