Build Error when using -DCMAKE_CXX_FLAGS_DEBUG="/MTd" flag in C++

Hi,

I am facing build error, when using -DCMAKE_CXX_FLAGS_DEBUG="/MTd" .

cmake_code:

cmake …\ITK -DCMAKE_CXX_FLAGS_RELEASE="/MT" -DCMAKE_CXX_FLAGS_DEBUG="/MTd" -DITK_SKIP_PATH_LENGTH_CHECKS=ON -DModule_ITKIOGDCM=OFF -DModule_ITKGDCMIO=OFF -DITK_USE_SYSTEM_JPEG=OFF -DITK_USE_SYSTEM_PNG=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF -G “Visual Studio 15 2017 Win64”

After Building . i have added following comment:

cmake.exe --build . --config Debug --target ALL_BUILD

Error:

“E:\test1\New folder\1\build_MTD\ALL_BUILD.vcxproj” (default target) (1) ->
“E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\ITKTestKernel-all.vcxproj” (default target) (238) ->
“E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj” (default target) (239) ->
(Link target) ->
ITKniftiio-5.1.lib(nifti1_io.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\1\bu
ild_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_win32.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\1\build
_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder
\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKgiftiio-5.1.lib(gifti_io.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\1\bui
ld_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKgiftiio-5.1.lib(gifti_xml.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\1\bu
ild_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKEXPAT-5.1.lib(xmlparse.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\1\build
_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2019: unresolved external symbol __imp__aligned_free referenced in
function gdcmopenjp2opj_aligned_free [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj
]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2019: unresolved external symbol __imp__aligned_malloc referenced i
n function opj_aligned_alloc_n [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2019: unresolved external symbol __imp__aligned_realloc referenced
in function opj_aligned_realloc_n [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(pngrtran.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\1\build_MTD
\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_aux.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\1\build_MTD
\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(j2k.obj) : error LNK2001: unresolved external symbol _imp_floor [E:\test1\New folder\1\build
MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(dwt.obj) : error LNK2001: unresolved external symbol _imp_floor [E:\test1\New folder\1\build
MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(t1.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\1\build_M
TD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(png.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\1\build_MTD\Modu
les\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKniftiio-5.1.lib(nifti1_io.obj) : error LNK2019: unresolved external symbol __imp__fdclass referenced in function n
ifti_read_buffer [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKznz-5.1.lib(znzlib.obj) : error LNK2019: unresolved external symbol __imp_feof referenced in function znzeof [E:\t
est1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKznz-5.1.lib(znzlib.obj) : error LNK2019: unresolved external symbol __imp_fgets referenced in function znzgets [E:
\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKznz-5.1.lib(znzlib.obj) : error LNK2019: unresolved external symbol __imp_rewind referenced in function znzrewind
[E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKNrrdIO-5.1.lib(read.obj) : error LNK2019: unresolved external symbol __imp_fileno referenced in function itk__nrrd
Calloc [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKNrrdIO-5.1.lib(encodingRaw.obj) : error LNK2001: unresolved external symbol __imp_fileno [E:\test1\New folder\1\bu
ild_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(fileno.obi) : error LNK2001: unresolved external symbol __imp_fileno [E:\test1\New folder\1\build_MTD\Mo
dules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKNrrdIO-5.1.lib(gzio.obj) : error LNK2019: unresolved external symbol __imp_ferror referenced in function itk__nrrd
GzRead [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(pngwrite.obj) : error LNK2001: unresolved external symbol __imp_ferror [E:\test1\New folder\1\build_MT
D\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkjpeg-5.1.lib(jdatadst.obj) : error LNK2001: unresolved external symbol __imp_ferror [E:\test1\New folder\1\build_M
TD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(png.obj) : error LNK2019: unresolved external symbol __imp_modf referenced in function itk_png_ascii_f
rom_fp [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_dirinfo.obj) : error LNK2019: unresolved external symbol __imp_bsearch referenced in function itk
_TIFFFindField [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_luv.obj) : error LNK2019: unresolved external symbol __imp_rand referenced in function itk_LogL16
fromY [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzread.obj) : error LNK2019: unresolved external symbol __imp_close referenced in function itkzlib_gz
close_r [E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzwrite.obj) : error LNK2001: unresolved external symbol __imp_close [E:\test1\New folder\1\build_MTD
\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(close.obi) : error LNK2001: unresolved external symbol __imp_close [E:\test1\New folder\1\build_MTD\Modu
les\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzread.obj) : error LNK2019: unresolved external symbol __imp_read referenced in function gz_load [E:
\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(read.obi) : error LNK2001: unresolved external symbol __imp_read [E:\test1\New folder\1\build_MTD\Module
s\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzwrite.obj) : error LNK2019: unresolved external symbol __imp_write referenced in function gz_comp [
E:\test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp_write [E:\test1\New folder\1\build_MTD\Modu
les\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzlib.obj) : error LNK2019: unresolved external symbol __imp_open referenced in function gz_open [E:
test1\New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(open.obi) : error LNK2001: unresolved external symbol __imp_open [E:\test1\New folder\1\build_MTD\Module
s\Core\TestKernel\src\itkTestDriver.vcxproj]
E:\test1\New folder\1\build_MTD\bin\Debug\itkTestDriver.exe : fatal error LNK1120: 18 unresolved externals [E:\test1
New folder\1\build_MTD\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]

337 Warning(s)
38 Error(s)

how to solve this error, in my cmake any flags are missed ? if i missed any flag ,please tell me what flag i missed.

Thanks!

You are seriously modifying default Visual Studio’s flags. For release you are requesting static multi-threaded standard run-time library. For debug, you are requesting dynamic debug multi-threaded standard run-time library. The usual way is both are either static or dynamic (DLL). What are you trying to accomplish?

Maybe start from defaults, and then modify them. Get the defaults by running CMake or CMake-GUI without any custom options. For example, default CMAKE_CXX_FLAGS_DEBUG = /MDd /Zi /Ob0 /Od /RTC1.

Hi dzenanz !
Thanks For your Response.

For release you are requesting static multi-threaded standard run-time library.-yes correct.

For debug, you are requesting dynamic debug multi-threaded standard run-time library.-Debug also i am requesting MTd(static Multi threaded debug standard run-time library) .not requesting MDd(Multi threaded Debug Dll)

I am trying to build both Debug and release as static multi-threaded runtime Library.

You are right, I did not pay enough attention.

You also need to use the same flags for CMAKE_C_FLAGS in addition to CMAKE_CXX_FLAGS. I still think starting from CMake defaults and modifying what you want is better than building flags from scratch.

Hi dzenanz !

i used this flags CMAKE_C_FLAGS CMAKE_CXX_FLAGS .still facing same error only.

CMAKE:

cmake ..\ITK -DCMAKE_CXX_FLAGS_RELEASE="/MT" -DCMAKE_C_FLAGS="/MTd" -DCMAKE_CXX_FLAGS_DEBUG="/MTd" -DITK_SKIP_PATH_LENGTH_CHECKS=ON -DModule_ITKIOGDCM=OFF -DModule_ITKGDCMIO=OFF -DITK_USE_SYSTEM_JPEG=OFF -DITK_USE_SYSTEM_PNG=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF -G "Visual Studio 15 2017 Win64"

ERROR

“E:\test1\New folder\2\build1\ALL_BUILD.vcxproj” (default target) (1) ->
“E:\test1\New folder\2\build1\Modules\Core\TestKernel\ITKTestKernel-all.vcxproj” (default target) (238) ->
“E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj” (default target) (239) ->
(Link target) ->
ITKniftiio-5.1.lib(nifti1_io.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\2\bu
ild1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_win32.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\2\build
1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder
\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKgiftiio-5.1.lib(gifti_io.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\2\bui
ld1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKgiftiio-5.1.lib(gifti_xml.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\2\bu
ild1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKEXPAT-5.1.lib(xmlparse.obj) : error LNK2001: unresolved external symbol __imp_realloc [E:\test1\New folder\2\build
1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2019: unresolved external symbol __imp__aligned_free referenced in
function gdcmopenjp2opj_aligned_free [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2019: unresolved external symbol __imp__aligned_malloc referenced i
n function opj_aligned_alloc_n [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(opj_malloc.obj) : error LNK2019: unresolved external symbol __imp__aligned_realloc referenced
in function opj_aligned_realloc_n [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(pngrtran.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\2\build1\Mo
dules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_aux.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\2\build1\Mo
dules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(j2k.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\2\build1
\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(dwt.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\2\build1
\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkgdcmopenjp2-5.1.lib(t1.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\2\build1
Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(png.obj) : error LNK2001: unresolved external symbol __imp_floor [E:\test1\New folder\2\build1\Modules
\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKniftiio-5.1.lib(nifti1_io.obj) : error LNK2019: unresolved external symbol __imp__fdclass referenced in function n
ifti_read_buffer [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKznz-5.1.lib(znzlib.obj) : error LNK2019: unresolved external symbol __imp_feof referenced in function znzeof [E:\t
est1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKznz-5.1.lib(znzlib.obj) : error LNK2019: unresolved external symbol __imp_fgets referenced in function znzgets [E:
\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKznz-5.1.lib(znzlib.obj) : error LNK2019: unresolved external symbol __imp_rewind referenced in function znzrewind
[E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKNrrdIO-5.1.lib(read.obj) : error LNK2019: unresolved external symbol __imp_fileno referenced in function itk__nrrd
Calloc [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKNrrdIO-5.1.lib(encodingRaw.obj) : error LNK2001: unresolved external symbol __imp_fileno [E:\test1\New folder\2\bu
ild1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(fileno.obi) : error LNK2001: unresolved external symbol __imp_fileno [E:\test1\New folder\2\build1\Modul
es\Core\TestKernel\src\itkTestDriver.vcxproj]
ITKNrrdIO-5.1.lib(gzio.obj) : error LNK2019: unresolved external symbol __imp_ferror referenced in function itk__nrrd
GzRead [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(pngwrite.obj) : error LNK2001: unresolved external symbol __imp_ferror [E:\test1\New folder\2\build1\M
odules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkjpeg-5.1.lib(jdatadst.obj) : error LNK2001: unresolved external symbol __imp_ferror [E:\test1\New folder\2\build1
Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkpng-5.1.lib(png.obj) : error LNK2019: unresolved external symbol __imp_modf referenced in function itk_png_ascii_f
rom_fp [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_dirinfo.obj) : error LNK2019: unresolved external symbol __imp_bsearch referenced in function itk
_TIFFFindField [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itktiff-5.1.lib(tif_luv.obj) : error LNK2019: unresolved external symbol __imp_rand referenced in function itk_LogL16
fromY [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzread.obj) : error LNK2019: unresolved external symbol __imp_close referenced in function itkzlib_gz
close_r [E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzwrite.obj) : error LNK2001: unresolved external symbol __imp_close [E:\test1\New folder\2\build1\Mo
dules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(close.obi) : error LNK2001: unresolved external symbol __imp_close [E:\test1\New folder\2\build1\Modules
\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzread.obj) : error LNK2019: unresolved external symbol __imp_read referenced in function gz_load [E:
\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(read.obi) : error LNK2001: unresolved external symbol __imp_read [E:\test1\New folder\2\build1\Modules\C
ore\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzwrite.obj) : error LNK2019: unresolved external symbol __imp_write referenced in function gz_comp [
E:\test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp_write [E:\test1\New folder\2\build1\Modules
\Core\TestKernel\src\itkTestDriver.vcxproj]
itkzlib-5.1.lib(gzlib.obj) : error LNK2019: unresolved external symbol __imp_open referenced in function gz_open [E:
test1\New folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]
OLDNAMES.lib(open.obi) : error LNK2001: unresolved external symbol __imp_open [E:\test1\New folder\2\build1\Modules\C
ore\TestKernel\src\itkTestDriver.vcxproj]
E:\test1\New folder\2\build1\bin\Debug\itkTestDriver.exe : fatal error LNK1120: 18 unresolved externals [E:\test1\New
folder\2\build1\Modules\Core\TestKernel\src\itkTestDriver.vcxproj]

337 Warning(s)
38 Error(s)

CMAKE_C_FLAGS_DEBUG take priority over CMAKE_C_FLAGS. If you also set CMAKE_C_FLAGS_DEBUG to /MTd the build succeeds. Your release config flags are even more obviously unsynchronized. Take a look at the configuration in CMake-GUI to see all the options. Here is a screenshot of configuration which built fine in Debug mode:

1 Like