This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I know LNK2019 is related to unlinked librarys. I know the drill -> Linker - > Input -> Additional Dependencies. I've done that with the libs provided by Basler (HERE). FYI Basler is a camera manufacturer and i need to talk to the camera via their c++ API.
I wanted to start today with a new project and thought it would be a good start to compile their 'grab a single frame' sample file.
Well in Linux with g++ everything works like a charm and compiling is a thing of a minute but sadly i need Windows for this project for stupid reasons.
I'm working on this now for 4 hours and i'm beginning to go crazy.
Help is much appreciated. Here is the Main File and all Project Info from Visual Studio:
// Grab.cpp
/*
Note: Before getting started, Basler recommends reading the Programmer's Guide topic
in the pylon C++ API documentation that gets installed with pylon.
If you are upgrading to a higher major version of pylon, Basler also
strongly recommends reading the Migration topic in the pylon C++ API documentation.
This sample illustrates how to grab and process images using the CInstantCamera class.
The images are grabbed and processed asynchronously, i.e.,
while the application is processing a buffer, the acquisition of the next buffer is done
in parallel.
The CInstantCamera class uses a pool of buffers to retrieve image data
from the camera device. Once a buffer is filled and ready,
the buffer can be retrieved from the camera object for processing. The buffer
and additional image data are collected in a grab result. The grab result is
held by a smart pointer after retrieval. The buffer is automatically reused
when explicitly released or when the smart pointer object is destroyed.
*/
// Include files to use the PYLON API.
#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
// Namespace for using pylon objects.
using namespace Pylon;
// Namespace for using cout.
using namespace std;
// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 100;
int main(int argc, char* argv[])
{
// The exit code of the sample application.
int exitCode = 0;
// Automagically call PylonInitialize and PylonTerminate to ensure the pylon runtime system
// is initialized during the lifetime of this object.
Pylon::PylonAutoInitTerm autoInitTerm;
try
{
// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
// Print the model name of the camera.
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
// The parameter MaxNumBuffer can be used to control the count of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5;
// Start the grabbing of c_countOfImagesToGrab images.
// The camera device is parameterized with a default configuration which
// sets up free-running continuous acquisition.
camera.StartGrabbing( c_countOfImagesToGrab);
// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;
// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
while ( camera.IsGrabbing())
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
// Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded())
{
// Access the image data.
cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
#ifdef PYLON_WIN_BUILD
// Display the grabbed image.
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
else
{
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}
}
catch (GenICam::GenericException &e)
{
// Error handling.
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
// Comment the following two lines to disable waiting on exit.
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Included LibrariesFolder (Linker->Additional Dependencies):
"C:\pylon\pylon\lib\Win32";"
C:\pylon\genicam\library\cpp\lib\win32_i86"
They exist. I've checked that.
Output from Compiler:
1>------ Build started: Project: Grab, Configuration: Debug Win32 ------
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::PylonAutoInitTerm::PylonAutoInitTerm(void)" (__imp_??0PylonAutoInitTerm#Pylon##QAE#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::PylonAutoInitTerm::~PylonAutoInitTerm(void)" (__imp_??1PylonAutoInitTerm#Pylon##QAE#XZ) referenced in function __catch$_main$0
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CDeviceInfo::CDeviceInfo(void)" (__imp_??0CDeviceInfo#Pylon##QAE#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class GenICam::gcstring __thiscall Pylon::CDeviceInfo::GetModelName(void)const " (__imp_?GetModelName#CDeviceInfo#Pylon##QBE?AVgcstring#GenICam##XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Pylon::CDeviceInfo::~CDeviceInfo(void)" (__imp_??1CDeviceInfo#Pylon##UAE#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class Pylon::CTlFactory & __cdecl Pylon::CTlFactory::GetInstance(void)" (__imp_?GetInstance#CTlFactory#Pylon##SAAAV12#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall Pylon::CGrabResultData::GrabSucceeded(void)const " (__imp_?GrabSucceeded#CGrabResultData#Pylon##QBE_NXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class GenICam::gcstring __thiscall Pylon::CGrabResultData::GetErrorDescription(void)const " (__imp_?GetErrorDescription#CGrabResultData#Pylon##QBE?AVgcstring#GenICam##XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall Pylon::CGrabResultData::GetErrorCode(void)const " (__imp_?GetErrorCode#CGrabResultData#Pylon##QBEIXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall Pylon::CGrabResultData::GetWidth(void)const " (__imp_?GetWidth#CGrabResultData#Pylon##QBEIXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall Pylon::CGrabResultData::GetHeight(void)const " (__imp_?GetHeight#CGrabResultData#Pylon##QBEIXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void * __thiscall Pylon::CGrabResultData::GetBuffer(void)const " (__imp_?GetBuffer#CGrabResultData#Pylon##QBEPAXXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CGrabResultPtr::CGrabResultPtr(void)" (__imp_??0CGrabResultPtr#Pylon##QAE#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CGrabResultPtr::~CGrabResultPtr(void)" (__imp_??1CGrabResultPtr#Pylon##QAE#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class Pylon::CGrabResultData * __thiscall Pylon::CGrabResultPtr::operator->(void)const " (__imp_??CCGrabResultPtr#Pylon##QBEPAVCGrabResultData#1#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CGrabResultPtr::operator struct Pylon::IImage &(void)const " (__imp_??BCGrabResultPtr#Pylon##QBEAAUIImage#1#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Pylon::CInstantCamera::CInstantCamera(struct Pylon::IPylonDevice *,enum Pylon::ECleanup)" (__imp_??0CInstantCamera#Pylon##QAE#PAUIPylonDevice#1#W4ECleanup#1##Z) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Pylon::CInstantCamera::~CInstantCamera(void)" (__imp_??1CInstantCamera#Pylon##UAE#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall Pylon::CInstantCamera::StartGrabbing(unsigned int,enum Pylon::EGrabStrategy,enum Pylon::EGrabLoop)" (__imp_?StartGrabbing#CInstantCamera#Pylon##UAEXIW4EGrabStrategy#2#W4EGrabLoop#2##Z) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall Pylon::CInstantCamera::RetrieveResult(unsigned int,class Pylon::CGrabResultPtr &,enum Pylon::ETimeoutHandling)" (__imp_?RetrieveResult#CInstantCamera#Pylon##UAE_NIAAVCGrabResultPtr#2#W4ETimeoutHandling#2##Z) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual bool __thiscall Pylon::CInstantCamera::IsGrabbing(void)const " (__imp_?IsGrabbing#CInstantCamera#Pylon##UBE_NXZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class Pylon::CDeviceInfo const & __thiscall Pylon::CInstantCamera::GetDeviceInfo(void)const " (__imp_?GetDeviceInfo#CInstantCamera#Pylon##UBEABVCDeviceInfo#2#XZ) referenced in function _main
1>Grab.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl Pylon::DisplayImage(unsigned int,struct Pylon::IImage const &)" (__imp_?DisplayImage#Pylon##YAXIABUIImage#1##Z) referenced in function _main
1>C:\path-to\Grab.exe : fatal error LNK1120: 23 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Pls can somebody tell me, what is going on ?
The linker is trying to compile your application, but cannot as it doesn't know what the various Pylon functions refer to as you haven't used the PylonBase_MD_VC100.lib library.
You may think you have, but you haven't. Let's explain why:
Included LibrariesFolder (Linker->Additional Dependencies):
"C:\pylon\pylon\lib\Win32";"
C:\pylon\genicam\library\cpp\lib\win32_i86"
They exist. I've checked that.
Well, no. You need to point the compiler to the file of the library (in this case, PylonBase_MD_VC100.lib), the folder won't suffice. Link to the library, and it'll work:
Linker->Additional Dependencies > Add the PylonBase_MD_VC100.lib library
OR
#prama comment(lib, "PylonBase_MD_VC100.lib") at the beginning of your code, just below any #includes
The following sample from the MSDN KB article on this issue will guarantee a LNK2019 error:
// LNK2019.cpp
// LNK2019 expected
extern char B[100]; // B is not available to the linker
int main() {
B[0] = ' ';
}
Related
I have a project in which cmake generation passes correctly. But, when I try to build I receive 2800+ error with LNK2001 or LNK2019 code: inresolved external symbol. Some examples:
C:\Projects\client\out\build\x32-Debug\worker.lib(worker.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: double __thiscall QRectF::left(void)const " (__imp_?left#QRectF##QBENXZ) referenced in function "public: class QStringList __thiscall Worker::readData(struct MinImg const &)" (?readBarcodes#Worker##QAE?AVQStringList##ABUMinImg###Z)
C:\Projects\client\out\build\x32-Debug\worker.lib(worker.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: double __thiscall QRectF::top(void)const " (__imp_?top#QRectF##QBENXZ) referenced in function "public: class QStringList __thiscall Worker::readData(struct MinImg const &)" (?readBarcodes#Worker##QAE?AVQStringList##ABUMinImg###Z)
C:\Projects\client\out\build\x32-Debug\worker.lib(worker.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: double __thiscall QRectF::width(void)const " (__imp_?width#QRectF##QBENXZ) referenced in function "public: class QStringList __thiscall Worker::readData(struct MinImg const &)" (?readBarcodes#Worker##QAE?AVQStringList##ABUMinImg###Z)
C:\Projects\client\out\build\x32-Debug\worker.lib(worker.cpp.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: double __thiscall QRectF::height(void)const " (__imp_?height#QRectF##QBENXZ) referenced in function "public: class QStringList __thiscall Worker::readData(struct MinImg const &)" (?readBarcodes#Worker##QAE?AVQStringList##ABUMinImg###Z)
The same applies to every class which is contained by Qt. In other words, compiler doesn't see Qt directory ('C:\Qt\5.15.2\msvc2019_64'). Toolset is set to msvc2019_x86. I tried the decision from here and also tried to add
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.15.2\\msvc2019_64\\")
to the root CMakeLists.txt file - nothing helps.
I tried both VS 2019 and 2022.
firstely tap this line in your CMD
set QTDIR "C:\Qt\5.15.2\msvc2019_64\bin"
secondely make this line in your cmakelistes.txt
set(CMAKE_PREFIX_PATH $ENV{QTDIR})
I am trying to read HDF5 file, this's the first time I come across this file format so please bare with me. The issue that I am having right now is linking the hdf5 lib to my project on Visual Studio 2017.
This's what I've done so far:
Linker > Input > Additional Dependencies contains hdf5.lib
Linker > General > Additional Libraries Directories contains path to lib directory of my HDF5 installation
C/C++ > General > Additional Include Directories contains path to include directory of my HDF5 installation
I've add to PATH variable bin directory of my HDF5 installation
Following the steps of the solution proposed here.
However, I still have the following linker errors when I try to build my project.
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: __cdecl H5::DataSpace::DataSpace(int,unsigned __int64 const *,unsigned __int64 const *)" (??0DataSpace#H5##QEAA#HPEB_K0#Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: int __cdecl H5::DataSpace::getSimpleExtentDims(unsigned __int64 *,unsigned __int64 *)const " (?getSimpleExtentDims#DataSpace#H5##QEBAHPEA_K0#Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl H5::DataSpace::~DataSpace(void)" (??1DataSpace#H5##UEAA#XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: class H5::DataSet __cdecl H5::H5Location::openDataSet(char const *,class H5::DSetAccPropList const &)const " (?openDataSet#H5Location#H5##QEBA?AVDataSet#2#PEBDAEBVDSetAccPropList#2##Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: enum H5T_class_t __cdecl H5::AbstractDs::getTypeClass(void)const " (?getTypeClass#AbstractDs#H5##QEBA?AW4H5T_class_t##XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual class H5::DataSpace __cdecl H5::DataSet::getSpace(void)const " (?getSpace#DataSet#H5##UEBA?AVDataSpace#2#XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: void __cdecl H5::DataSet::read(void *,class H5::DataType const &,class H5::DataSpace const &,class H5::DataSpace const &,class H5::DSetMemXferPropList const &)const " (?read#DataSet#H5##QEBAXPEAXAEBVDataType#2#AEBVDataSpace#2#2AEBVDSetMemXferPropList#2##Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl H5::DataSet::~DataSet(void)" (??1DataSet#H5##UEAA#XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: __cdecl H5::H5File::H5File(char const *,unsigned int,class H5::FileCreatPropList const &,class H5::FileAccPropList const &)" (??0H5File#H5##QEAA#PEBDIAEBVFileCreatPropList#1#AEBVFileAccPropList#1##Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual void __cdecl H5::H5File::close(void)" (?close#H5File#H5##UEAAXXZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl H5::H5File::~H5File(void)" (??1H5File#H5##UEAA#XZ) referenced in function main
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::DataSpace const & const H5::DataSpace::ALL" (?ALL#DataSpace#H5##2AEBV12#EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT" (?DEFAULT#FileAccPropList#H5##2AEBV12#EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::FileCreatPropList const & const H5::FileCreatPropList::DEFAULT" (?DEFAULT#FileCreatPropList#H5##2AEBV12#EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::DSetMemXferPropList const & const H5::DSetMemXferPropList::DEFAULT" (?DEFAULT#DSetMemXferPropList#H5##2AEBV12#EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::DSetAccPropList const & const H5::DSetAccPropList::DEFAULT" (?DEFAULT#DSetAccPropList#H5##2AEBV12#EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::PredType const & const H5::PredType::NATIVE_FLOAT" (?NATIVE_FLOAT#PredType#H5##2AEBV12#EB)
1>C:\Users\maxim\source\repos\EigenExperiment\x64\Debug\EigenExperiment.exe : fatal error LNK1120: 17 unresolved externals
1>Done building project "EigenExperiment.vcxproj" -- FAILED.
Also, I've attached the code I'm using, just in case I missed something.
Any hep is highly appreciated :)
#include <iostream>
#include <Eigen/Dense>
#include <filesystem>
#include <math.h>
#include "H5Cpp.h"
#include <vector>
#include <string>
using namespace std;
using namespace H5;
int main()
{
string ifn = "basler.h5";
string datasetPath = "/face_g_tobii/data";
// Open HDF5 file handle, read only
H5File fp(ifn.c_str(), H5F_ACC_RDONLY);
// access the required dataset by path name
DataSet dset = fp.openDataSet(datasetPath.c_str());
// get the dataspace
DataSpace dspace = dset.getSpace();
// get the dataset type class
H5T_class_t type_class = dset.getTypeClass();
// According to HDFView, this is a 32-bit floating-point
// get the size of the dataset
hsize_t rank;
hsize_t dims[2];
rank = dspace.getSimpleExtentDims(dims, NULL); // rank = 1
cout << "Datasize: " << dims[0] << endl; // this is the correct number of values
// Define the memory dataspace
hsize_t dimsm[1];
dimsm[0] = dims[0];
DataSpace memspace(1, dimsm);
// create a vector the same size as the dataset
vector<float> data;
data.resize(dims[0]);
cout << "Vectsize: " << data.size() << endl;
float data_out[65341];
for (int i = 0; i < 65341; i++)
{
data_out[i] = 0;
}
// pass pointer to the array (or vector) to read function, along with the data type and space.
dset.read(data_out, PredType::NATIVE_FLOAT, memspace, dspace); // FAILS
dset.read(data_out, PredType::NATIVE_FLOAT, dspace); // FAILS
dset.read(data.data(), PredType::NATIVE_FLOAT, memspace, dspace); // FAILS
// close the HDF5 file
fp.close();
}
It turned out the external libraries should be named first, what worked for me was:
1.4 Select Linker->Input and beginning with the
"Additional Dependencies" line, enter the library names. The
external libraries should be listed first, followed by the HDF5
library, and then optionally the HDF5 High Level, Fortran or C++
libraries. For example, to compile a C++ application, enter:
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib
This's from the documentation of HDF5, which I completely overlooked :/
i am trying with hdf5 for c++ on vs2019 and i did the stuff of adding
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib but then i canĀ“t find both libs szip and zlib. Of course i did "H5_BUILT_AS_DYNAMIC_LIB" at preprocessor, but nothing.
According to the error, the project you built is the x64 version, I suggest you check whether the linked hdf5.lib is 32-bit or 64-bit? You should use the 64-bit hdf5.
And I suggest you could try to check whether the platform and the Configuration selection in the property page is x64 and debug.
I suggest you could select "All Platforms" for the platform and select "All Configurations" for the Configuration when changing the properties.
I'm trying to build this simple ZeroMQ server in C++ on Visual Studio 2013.
#include "stdafx.h"
#include "zmq.hpp"
#include <string>
#include <iostream>
#include <windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// Prepare context and socket
zmq::context_t ctx(1);
zmq::socket_t sckt(ctx, ZMQ_REP);
sckt.bind("tcp://*:5555");
while (true) {
zmq::message_t request;
// Wait for next request from client
sckt.recv(&request);
std::cout << "Received Hello" << endl;
Sleep(1);
// Send reply back to client
zmq::message_t reply(5);
memcpy((void*)reply.data(), "World", 5);
sckt.send(reply);
}
return EXIT_SUCCESS;
}
However, I'm getting error LNK2019 when I try to build the VS project. Below is the compiler output:
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_errno referenced in function "public: __thiscall zmq::error_t::error_t(void)" (??0error_t#zmq##QAE#XZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_strerror referenced in function "public: virtual char const * __thiscall zmq::error_t::what(void)const " (?what#error_t#zmq##UBEPBDXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_ctx_new referenced in function "public: __thiscall zmq::context_t::context_t(int,int)" (??0context_t#zmq##QAE#HH#Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_ctx_set referenced in function "public: __thiscall zmq::context_t::context_t(int,int)" (??0context_t#zmq##QAE#HH#Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_ctx_destroy referenced in function "public: void __thiscall zmq::context_t::close(void)" (?close#context_t#zmq##QAEXXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_init referenced in function "public: __thiscall zmq::message_t::message_t(void)" (??0message_t#zmq##QAE#XZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_init_size referenced in function "public: __thiscall zmq::message_t::message_t(unsigned int)" (??0message_t#zmq##QAE#I#Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_send referenced in function "public: bool __thiscall zmq::socket_t::send(class zmq::message_t &,int)" (?send#socket_t#zmq##QAE_NAAVmessage_t#2#H#Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_recv referenced in function "public: bool __thiscall zmq::socket_t::recv(class zmq::message_t *,int)" (?recv#socket_t#zmq##QAE_NPAVmessage_t#2#H#Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_close referenced in function "public: __thiscall zmq::message_t::~message_t(void)" (??1message_t#zmq##QAE#XZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_data referenced in function "public: void * __thiscall zmq::message_t::data(void)" (?data#message_t#zmq##QAEPAXXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_socket referenced in function "public: __thiscall zmq::socket_t::socket_t(class zmq::context_t &,int)" (??0socket_t#zmq##QAE#AAVcontext_t#1#H#Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_close referenced in function "public: void __thiscall zmq::socket_t::close(void)" (?close#socket_t#zmq##QAEXXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_bind referenced in function "public: void __thiscall zmq::socket_t::bind(char const *)" (?bind#socket_t#zmq##QAEXPBD#Z)
1>D:\[ Source Code ]\C++\ZeroMQServer\Debug\ZeroMQServer.exe : fatal error LNK1120: 14 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have installed the ZeroMQ binary v4.0.4 and updated the VS project properties to point to ZeroMQ's include and lib paths. Specifically, this is what I have updated in the project properties (I suspect some of these settings may be redundant):
Configuration Properties > VC++ Directories > Include Directories: Added '$(ZEROMQ_HOME)\include'
Configuration Properties > VC++ Directories > Library Directories: Added '$(ZEROMQ_HOME)\lib'
Configuration Properties > C/C++ > General > Additional Include Directories: Added '$(ZEROMQ_HOME)\include'
Configuration Properties > Linker > Input > Additional Dependencies: Added 'libzmq-v120-mt-4_0_4.lib;libzmq-v120-mt-gd-4_0_4.lib'
I'm on Win 7, 64-bit Edition.
Please help me resolve this.
According to the library names on zeromq.org, you are trying to link the same library twice: first with the release version, and then with the debug versions.
Remove libzmq-v120-mt-gd-4_0_4.lib from your Release configuration, and remove libzmq-v120-mt-4_0_4.lib from your Debug configuration.
[edit]
Your application probably is 32bit, and the library you are trying to link with is 64bit. (You can use dumpbin to determine what architecture a .lib file is for, see this answer for an example. Please use the 32bit library, or change your application to 64bit.
I had to define ZMQ_STATIC since I wanted to link zmq statically.
By default all these functions defined as
elif defined DLL_EXPORT
define ZMQ_EXPORT __declspec(dllexport)
I had the same errors. But for me they were produced by a wrong set calling convention.
(Just wanted to mention it here because it cost me more than a hour to track it.)
I recently started again on a C++ application. I am using NetLink for Sockets and Visual Studio for developing.
I made a small code but I got some errors. I've included the files from NetLink and I added ws2_32.lib (in linker/general & as pragma comment), but I still got these errors:
Error 1 error LNK2019: unresolved external symbol "void __cdecl NL::init(void)" (?init#NL##YAXXZ) referenced in function _main c:\Users\Joshua\documents\visual studio 2012\Projects\OBPP\OBPP\Main.obj
Error 4 error LNK2019: unresolved external symbol "public: class NL::Socket * __thiscall NL::Socket::accept(void)" (?accept#Socket#NL##QAEPAV12#XZ) referenced in function "private: virtual void __thiscall OnAccept::exec(class NL::Socket *,class NL::SocketGroup *,void *)" (?exec#OnAccept##EAEXPAVSocket#NL##PAVSocketGroup#3#PAX#Z) c:\Users\Joshua\documents\visual studio 2012\Projects\OBPP\OBPP\Main.obj
Error 6 error LNK2019: unresolved external symbol "public: bool __thiscall NL::SocketGroup::listen(unsigned int,void *)" (?listen#SocketGroup#NL##QAE_NIPAX#Z) referenced in function _main c:\Users\Joshua\documents\visual studio 2012\Projects\OBPP\OBPP\Main.obj
Error 5 error LNK2019: unresolved external symbol "public: __thiscall NL::SocketGroup::SocketGroup(void)" (??0SocketGroup#NL##QAE#XZ) referenced in function _main c:\Users\Joshua\documents\visual studio 2012\Projects\OBPP\OBPP\Main.obj
Error 2 error LNK2019: unresolved external symbol "public: __thiscall NL::Socket::Socket(unsigned int,enum NL::Protocol,enum NL::IPVer,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int)" (??0Socket#NL##QAE#IW4Protocol#1#W4IPVer#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##I#Z) referenced in function _main c:\Users\Joshua\documents\visual studio 2012\Projects\OBPP\OBPP\Main.obj
Error 3 error LNK2019: unresolved external symbol "public: __thiscall NL::Socket::~Socket(void)" (??1Socket#NL##QAE#XZ) referenced in function _main c:\Users\Joshua\documents\visual studio 2012\Projects\OBPP\OBPP\Main.obj
Error 7 error LNK1120: 6 unresolved externals c:\users\joshua\documents\visual studio 2012\Projects\OBPP\Debug\OBPP.exe
Code I'm using (just wanted to try out accepting):
#include <iostream>
#include "netlink\socket.h"
#include "netlink\socket_group.h"
#pragma comment(lib, "Ws2_32.lib")
#define PORT 30000
class OnAccept: public NL::SocketGroupCmd {
void exec(NL::Socket* socket, NL::SocketGroup* group, void* reference) {
NL::Socket* newConnection = socket->accept();
group->add(newConnection);
std::cout << "\nConnection " << newConnection->hostTo() << ":" << newConnection->portTo() << " added...";
std::cout.flush();
}
};
int main()
{
NL::init();
NL::Socket s(PORT);
NL::SocketGroup group;
group.setCmdOnAccept(&OnAccept());
group.add(&s);
if (group.listen(2000))
{
std::cout << "Listening on Sockets, port " << PORT << std::endl;
}
getchar();
}
I am the developer of the library. It can't be used with the headers only, you need to link the static/dynamic compiled library.
You have to build the library first, to generate the .lib file. Once you have the netLink.lib file built (or whatever you name it) you have to add that dependency to the linker.
I am not visual studio developer, But error message says unresolved external symbol means linker is not able to find some symbols.
Look at you linking command does it include Netlink library?
I'm trying to use Task Schedule throulg Visual c++. I'm using Ctask.h (from here)
to do the task. However, when I build the solution (using Visual Studio 11), it says
fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
When I switch to /MD, it gives this error
ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: __thiscall CTask::CTask(void)" (??0CTask##QAE#XZ) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetStartDateTime(class ATL::CTime const &)" (?SetStartDateTime#CTask##QAEXABVCTime#ATL###Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetFrequency(enum CTask::ETaskFrequency)" (?SetFrequency#CTask##QAEXW4ETaskFrequency#1##Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetProgram(wchar_t const *)" (?SetProgram#CTask##QAEXPB_W#Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetAccountName(wchar_t const *)" (?SetAccountName#CTask##QAEXPB_W#Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: long __thiscall CTask::SaveTask(wchar_t const *,int)const " (?SaveTask#CTask##QBEJPB_WH#Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CTask::~CTask(void)" (??1CTask##UAE#XZ) referenced in function _wmain
same is the case with other linking option. This is thecode I've typed:
#include "stdafx.h"
#include "CTask.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CTask task;
CTime time(2013, 03, 15, 7, 11, 0);
LPCTSTR sTaskName( L"Task Name" );
BOOL replace = TRUE;
task.SetProgram( L"E:\\aaa.txt" );
task.SetAccountName( L"harshilsharma63" );
task.SetStartDateTime( time );
task.SetFrequency( CTask::freqOnce );
if( S_OK == task.SaveTask( sTaskName, replace))
{
cout << "task successfully created!";
return 0;
}
else
{
cout << "task creation failed!";
return 1;
}
return 0;
}
I have already set "Use MFC in" to "Use MFC in shared DLL".
I don't see any indication that you actually have put the CTask.cpp into your project. Including the header only will result in the linker errors you see, you need the .cpp, too.
You need add to your project the CTask.cpp as well as CTask.h. The original project http://www.codeproject.com/Articles/13089/Harnessing-the-task-scheduler can be compiled without any trouble - I just checked it!