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.
Related
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] = ' ';
}
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.)
error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class std::locale::id std::codecvt::id" (__imp_?id#?$codecvt#DDH#std##2V0locale#2#A)
1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::codecvt::_Getcat(class std::locale::facet const * *,class std::locale const *)" (__imp_?_Getcat#?$codecvt#DDH#std##SAIPAPBVfacet#locale#2#PBV42##Z)
1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int
__thiscall std::codecvt::unshift(int &,char *,char *,char * &)const " (__imp_?unshift#?$codecvt#DDH#std##QBEHAAHPAD1AAPAD#Z)
1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt::out(int &,char const *,char const *,char const * &,char *,char *,char * &)const " (__imp_?out#?$codecvt#DDH#std##QBEHAAHPBD1AAPBDPAD3AAPAD#Z)
1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt::in(int &,char const *,char const *,char const * &,char *,char *,char * &)const " (__imp_?in#?$codecvt#DDH#std##QBEHAAHPBD1AAPBDPAD3AAPAD#Z)
1>C:\perforce\sw\apps\gpu\drivers\common\logassert\Release\logassert.dll : fatal error LNK1120: 5 unresolved externals
Issue Explanation:
Now I'm seeing above linking error when I add this source line "ifstream fin;" to source file. If I remove this source line then code successfully compiles. I already added supported header files and and namespace for ifstream object. Not sure, why I'm seeing this linking error. Searched similar error on SO and tried their suggested solutions but those solution didn't work for me. Any idea?
SAMPLE CODE
//In stdafx.h file below code is there
#pragma once
#include<iostream>
#include<fstream>
using namespace std;
//In program.cpp
#include "stdafx.h"
class A
{
void B();
ifstream fin; //now if I make this member static then issue goes away. Can anybody explain?
}
It looks like you're not linking against the standard library.
Since the error messages show __declspec, I'll suppose
a Windows environment, with Visual Studios. By default, this
should work: go into the properties of the project, then into
Linker: in General, Ignore Import Library should be No, and in
Input, Ignore All Default Libraries should be No, and Ignore
Specific Default Libraries should be empty. (These are the
defaults.)
Otherwise: this could be due to problems with your installation, e.g. if not all of the files are present.
How do I read this error message from Visual Studio? Any clues as to what exactly is missing? This is a complex project and guessing is a rather ineffective approach - I'd prefer to know exactly what to look for.
1>------ Build started: Project: Crypto, Configuration: debug_shared
x64 ------
1> Creating library ..\lib64\PocoCryptod.lib and object
..\lib64\PocoCryptod.exp 1>CipherImpl.obj : error LNK2019: unresolved
external symbol EVP_CIPHER_CTX_block_size referenced in function
"public: virtual unsigned __int64 __cdecl Poco::Crypto::`anonymous
namespace'::CryptoTransformImpl::blockSize(void)const "
(?blockSize#CryptoTransformImpl#?A0xbc3e4780#Crypto#Poco##UEBA_KXZ)
1>CipherImpl.obj : error LNK2019: unresolved external symbol
EVP_CipherInit referenced in function "public: __cdecl
Poco::Crypto::anonymous
namespace'::CryptoTransformImpl::CryptoTransformImpl(struct
evp_cipher_st const *,class std::vector<unsigned char,class
std::allocator<unsigned char> > const &,class std::vector<unsigned
char,class std::allocator<unsigned char> > const &,enum
Poco::Crypto::A0xbc3e4780::CryptoTransformImpl::Direction)"
(??0CryptoTransformImpl#?A0xbc3e4780#Crypto#Poco##QEAA#PEBUevp_cipher_st##AEBV?$vector#EV?$allocator#E#std###std##1W4Direction#0123##Z)
1>CipherImpl.obj : error LNK2019: unresolved external symbol
EVP_CipherUpdate referenced in function "public: virtual __int64
__cdecl Poco::Crypto::anonymous namespace'::CryptoTransformImpl::transform(unsigned char const
*,__int64,unsigned char *,__int64)" (?transform#CryptoTransformImpl#?A0xbc3e4780#Crypto#Poco##UEAA_JPEBE_JPEAE1#Z)
Full error list here
https://gist.github.com/anonymous/91a76564651be4ac43fc
You read it as
error LNK2019: unresolved external symbol EVP_CIPHER_CTX_block_size
The symbol EVP_CIPHER_CTX_block_size cannot be found.
referenced in function "public: virtual unsigned __int64 __cdecl Poco::Crypto::`anonymous namespace'::CryptoTransformImpl::blockSize(void)const " (?blockSize#CryptoTransformImpl#?A0xbc3e4780#Crypto#Poco##UEBA_KXZ)
You are attempting to use it in CryptoTransformImpl::blockSize(void)const (which is inside an anonymous namespace inside Poco::Crypto.
This can mean you didn't link against the library that exports that symbol.
EVP_.... are define in OpenSSL.
So you have to link with OpenSSL statically or dynamically.
You are missing the dll containing the EVP_CipherInit function in your library path.
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!