使用ITK库的C++项目qmake链接出现LINK2019未解析符号问题
gdcm::system::getHostName in ITK + qmake Project Got it, let's break down why this error is happening and walk through the fix step by step:
The Root Cause
Even though you're linking itkgdcmMSFF-4.13.lib, the gdcm::system::getHostName symbol isn't defined in that library. GDCM (which ITK wraps) splits its functionality into multiple modules, and this specific function lives in the gdcmCommon module. You're missing the corresponding ITK-wrapped gdcmCommon library in your link list.
Step-by-Step Fix
Add the missing gdcmCommon library to your
.prifile
Update your library linking section in the MyITK .pri file to include theitkgdcmCommon-4.13.lib(or its debug variant) alongside your existing libraries:# In your MyITK.pri file LIBS += -L$$ITK_LIB_DIR \ -lITKBiasCorrection-4.13 \ -lITKIOImageBase-4.13 \ -lITKNrrdIO-4.13 \ -litkgdcmMSFF-4.13 \ -litkgdcmCommon-4.13 # Add this lineHandle Debug/Release library variants (optional but recommended)
If your project uses separate Debug and Release configurations, use qmake's conditional logic to auto-select the correct library suffix (usuallydfor Debug builds):# In MyITK.pri, replace the single gdcmCommon line with this: CONFIG(debug, debug|release) { LIBS += -litkgdcmCommon-4.13d } else { LIBS += -litkgdcmCommon-4.13 }Rebuild your project
- Run
qmakeagain to pick up the updated library configuration - Clean and rebuild your project to ensure the new library is linked properly
- Run
Why This Works
ITK's GDCM integration mirrors GDCM's own module structure: gdcmMSFF (the main GDCM library) depends on gdcmCommon for utility functions like getHostName. By adding the missing itkgdcmCommon library, you're providing the linker with the definition for that unresolved symbol.
内容的提问来源于stack exchange,提问作者p.deman

