I am trying to link a 3rd party lib statically to my own .exe so that I only need to distribute one single .exe file. First, I built all the 3rd party static lib from source, generating several .lib files.
Then in visual studio, in my own project, I set Project->properties->C/C++->Code generation->Runtime Library to Multi-threaded (/MT)
. However, the linker would error
LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in ConsoleApplication1.obj
The latter part MT_StaticRelease
does make sense since I am trying static linking, while the former part MD_DynamicRelease
is absolutely wrong because I provided static lib. I set Project->properties->Linker->General->Additional Library Dependencies
to a folder that only contains *.lib
. And I am PRETTY SURE that these *.lib are static library instead of import library.
When I change to Project->properties->C/C++->Code generation->Runtime Library to Multi-threaded DLL (/MD)
, the build succeed.
It is really weird that visual studio recognize *.lib as dynamic lib.
- I've checked
%PATH%
to rule out any other possible polution. Do you have any ideas? - I've deleted all the cache from previous build.
#include "gdcmReader.h"
#ifdef _WIN32
#pragma comment(lib, "gdcmDSED")
#pragma comment(lib,"WS2_32")
#endif
typedef std::set<gdcm::DataElement> DataElementSet;
typedef DataElementSet::const_iterator ConstIterator;
int main(int argc, char *argv[])
{
if (argc < 2) {
std::cout << "Usage: xxxx.exe dicom_filename" << std::endl;
return 1;
}
const char *filename = argv[1];
gdcm::Reader reader;
reader.SetFileName(filename);
if (!reader.Read())
{
std::cerr << "Could not read: " << filename << std::endl;
return 1;
}
std::stringstream strm;
gdcm::File &file = reader.GetFile();
gdcm::DataSet &ds = file.GetDataSet();
gdcm::FileMetaInformation &fmi = file.GetHeader();
if (ds.FindDataElement(gdcm::Tag(0x10, 0x10))) {
const gdcm::DataElement &de = ds.GetDataElement(gdcm::Tag(0x10, 0x10));
std::cout << de << std::endl;
}
return 0;
}