tbeu / matio

MATLAB MAT File I/O Library
https://matio.sourceforge.io
BSD 2-Clause "Simplified" License
338 stars 97 forks source link

Problem during the linkage #160

Closed bkaangorur closed 3 years ago

bkaangorur commented 3 years ago

When I try to build matio via cmake, I get a linkage problem because of zlib. Here is the error that I get:

mingw32-make[2]: *** No rule to make target 'C:/aroot/stage/Library/lib/z.lib', needed by 'liblibmatio.dll'.  Stop.
mingw32-make[1]: *** [CMakeFiles\Makefile2:153: CMakeFiles/matio.dir/all] Error 2
mingw32-make: *** [Makefile:149: all] Error 2

I do not know where C:/aroot/stage/Library/lib/z.lib path comes from, because I do not have those directories.

I should also state that I can compile the matio library if I disable zlib, hdf5, mat73 support options.

Output of cmake -G "MinGW Makefiles" and cmake --build . commands are below: cmake_log.txt cmake_build_log.txt

tbeu commented 3 years ago

@MaartenBent Could you please have a look at it? Thanks. We do not run CMake CI tests with MinGW on Appveyor yet (only MSVC).

MaartenBent commented 3 years ago

Strange, in the log it finds a different ZLIB (Found ZLIB: D:/dev/Msys2/mingw64/lib/libz.dll.a). If I google the path in the error message it seems related to Anaconda.

Could you try adding to following to the beginning of CMakeLists.txt:

if(POLICY CMP0060)
    cmake_policy(SET CMP0060 NEW)
endif()

If that doesn't work, can you build verbose (cmake --build . -- VERBOSE=1) and share the output? If it uses response files, the content of those too please (e.g. linklibs.rsp).

MaartenBent commented 3 years ago

Also, for me it builds fine with msys2/mingw64. But I do notice that the libraries have a double lib prefix in both static and shared build (liblibmatio.a and liblibmatio.dll).

-- Found HDF5: hdf5-static (found version "1.12.0")
-- Found ZLIB: D:/msys64/mingw64/lib/libz.dll.a (found suitable version "1.2.11", minimum required is "1.2.3")
$ cmake --build . -- -j5
Scanning dependencies of target matio
[ 11%] Building C object CMakeFiles/matio.dir/src/mat.c.obj
[ 11%] Building C object CMakeFiles/matio.dir/src/endian.c.obj
[ 17%] Building C object CMakeFiles/matio.dir/src/io.c.obj
[ 23%] Building C object CMakeFiles/matio.dir/src/inflate.c.obj
[ 29%] Building C object CMakeFiles/matio.dir/src/mat73.c.obj
[ 35%] Building C object CMakeFiles/matio.dir/src/matvar_cell.c.obj
[ 41%] Building C object CMakeFiles/matio.dir/src/matvar_struct.c.obj
[ 47%] Building C object CMakeFiles/matio.dir/src/mat4.c.obj
[ 52%] Building C object CMakeFiles/matio.dir/src/mat5.c.obj
[ 58%] Building C object CMakeFiles/matio.dir/src/snprintf.c.obj
[ 64%] Building C object CMakeFiles/matio.dir/src/read_data.c.obj
[ 70%] Building RC object CMakeFiles/matio.dir/visual_studio/matio.rc.obj
[ 76%] Linking C static library liblibmatio.a
[ 76%] Built target matio
Scanning dependencies of target matdump
Scanning dependencies of target test_mat
[ 82%] Building C object CMakeFiles/matdump.dir/tools/matdump.c.obj
[ 88%] Building C object CMakeFiles/test_mat.dir/test/test_mat.c.obj
[ 94%] Linking C executable matdump.exe
[100%] Linking C executable test_mat.exe
[100%] Built target matdump
[100%] Built target test_mat
tbeu commented 3 years ago

But I do notice that the libraries have a double lib prefix in both static and shared build (liblibmatio.a and liblibmatio.dll).

That one likely is due to https://github.com/tbeu/matio/blob/d49cac47b9cb373920bf7f85a0f1bdcb1caf84bd/cmake/src.cmake#L63-L65.

MaartenBent commented 3 years ago

Yes, I suppose it should be if(MSVC) only.

I can create a PR to fix it, but I'll wait for a response to this issue in case something else needs to be fixed.

tbeu commented 3 years ago

Fine for me. Very good. Thanks.

bkaangorur commented 3 years ago

Strange, in the log it finds a different ZLIB (Found ZLIB: D:/dev/Msys2/mingw64/lib/libz.dll.a). If I google the path in the error message it seems related to Anaconda.

Could you try adding to following to the beginning of CMakeLists.txt:

if(POLICY CMP0060)
    cmake_policy(SET CMP0060 NEW)
endif()

If that doesn't work, can you build verbose (cmake --build . -- VERBOSE=1) and share the output? If it uses response files, the content of those too please (e.g. linklibs.rsp).

Unfortunately, Policy CMP0060 did not work. The result of build command with verbose is below. As you have already stated, it uses some paths from Anaconda. I am not exactly sure what you mean with .rsp files, but also added contents of .rsp files under CMakeFiles\matio.dir and CMakefiles\matdump.dir.

D:\dev\Msys2\mingw64\bin\cmake.exe -SD:\workspace\GitHub\matio -BD:\workspace\GitHub\matio --check-build-system CMakeFiles\Makefile.cmake 0
D:\dev\Msys2\mingw64\bin\cmake.exe -E cmake_progress_start D:\workspace\GitHub\matio\CMakeFiles D:\workspace\GitHub\matio\CMakeFiles\progress.marks
D:/dev/Msys2/mingw64/bin/mingw32-make.exe  -f CMakeFiles\Makefile2 all
mingw32-make[1]: Entering directory 'D:/workspace/GitHub/matio'
D:/dev/Msys2/mingw64/bin/mingw32-make.exe  -f CMakeFiles\matio.dir\build.make CMakeFiles/matio.dir/depend
mingw32-make[2]: Entering directory 'D:/workspace/GitHub/matio'
D:\dev\Msys2\mingw64\bin\cmake.exe -E cmake_depends "MinGW Makefiles" D:\workspace\GitHub\matio D:\workspace\GitHub\matio D:\workspace\GitHub\matio D:\workspace\GitHub\matio D:\workspace\GitHub\matio\CMakeFiles\matio.dir\DependInfo.cmake --color=
Dependee "D:\workspace\GitHub\matio\CMakeFiles\matio.dir\DependInfo.cmake" is newer than depender "D:/workspace/GitHub/matio/CMakeFiles/matio.dir/depend.internal".
Dependee "D:/workspace/GitHub/matio/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "D:/workspace/GitHub/matio/CMakeFiles/matio.dir/depend.internal".
Scanning dependencies of target matio
mingw32-make[2]: Leaving directory 'D:/workspace/GitHub/matio'
D:/dev/Msys2/mingw64/bin/mingw32-make.exe  -f CMakeFiles\matio.dir\build.make CMakeFiles/matio.dir/build
mingw32-make[2]: Entering directory 'D:/workspace/GitHub/matio'
[  5%] Building C object CMakeFiles/matio.dir/src/endian.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\endian.c.obj   -c D:\workspace\GitHub\matio\src\endian.c
[ 11%] Building C object CMakeFiles/matio.dir/src/mat.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\mat.c.obj   -c D:\workspace\GitHub\matio\src\mat.c
[ 17%] Building C object CMakeFiles/matio.dir/src/io.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\io.c.obj   -c D:\workspace\GitHub\matio\src\io.c
[ 23%] Building C object CMakeFiles/matio.dir/src/inflate.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\inflate.c.obj   -c D:\workspace\GitHub\matio\src\inflate.c
[ 29%] Building C object CMakeFiles/matio.dir/src/mat73.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\mat73.c.obj   -c D:\workspace\GitHub\matio\src\mat73.c
[ 35%] Building C object CMakeFiles/matio.dir/src/matvar_cell.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\matvar_cell.c.obj   -c D:\workspace\GitHub\matio\src\matvar_cell.c
[ 41%] Building C object CMakeFiles/matio.dir/src/matvar_struct.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\matvar_struct.c.obj   -c D:\workspace\GitHub\matio\src\matvar_struct.c
[ 47%] Building C object CMakeFiles/matio.dir/src/mat4.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\mat4.c.obj   -c D:\workspace\GitHub\matio\src\mat4.c
[ 52%] Building C object CMakeFiles/matio.dir/src/mat5.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\mat5.c.obj   -c D:\workspace\GitHub\matio\src\mat5.c
[ 58%] Building C object CMakeFiles/matio.dir/src/snprintf.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\snprintf.c.obj   -c D:\workspace\GitHub\matio\src\snprintf.c
[ 64%] Building C object CMakeFiles/matio.dir/src/read_data.c.obj
D:\dev\Msys2\mingw64\bin\gcc.exe -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS @CMakeFiles/matio.dir/includes_C.rsp  -o CMakeFiles\matio.dir\src\read_data.c.obj   -c D:\workspace\GitHub\matio\src\read_data.c
[ 70%] Building RC object CMakeFiles/matio.dir/visual_studio/matio.rc.obj
D:\dev\Msys2\mingw64\bin\windres.exe -O coff -DH5_BUILT_AS_DYNAMIC_LIB -Dmatio_EXPORTS -I D:\workspace\GitHub\matio\src -I C:\Users\kgorur\Anaconda3\Library\include -I D:\dev\Msys2\mingw64\include   D:\workspace\GitHub\matio\visual_studio\matio.rc CMakeFiles\matio.dir\visual_studio\matio.rc.obj
mingw32-make[2]: *** No rule to make target 'C:/aroot/stage/Library/lib/z.lib', needed by 'liblibmatio.dll'.  Stop.
mingw32-make[2]: Leaving directory 'D:/workspace/GitHub/matio'
mingw32-make[1]: *** [CMakeFiles\Makefile2:153: CMakeFiles/matio.dir/all] Error 2
mingw32-make[1]: Leaving directory 'D:/workspace/GitHub/matio'
mingw32-make: *** [Makefile:149: all] Error 2

CMakeFiles/matio.dir/includes_C.rsp:

-ID:/workspace/GitHub/matio/src -isystem C:/Users/kgorur/Anaconda3/Library/include 

CMakeFiles/matio.dir/linklibs.rsp:

 -lm C:/Users/kgorur/Anaconda3/Library/lib/hdf5.lib C:/aroot/stage/Library/lib/z.lib D:/dev/Msys2/mingw64/lib/libz.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 

CMakeFiles/matio.dir/objects1.rsp:

CMakeFiles/matio.dir/src/endian.c.obj CMakeFiles/matio.dir/src/mat.c.obj CMakeFiles/matio.dir/src/io.c.obj CMakeFiles/matio.dir/src/inflate.c.obj CMakeFiles/matio.dir/src/mat73.c.obj CMakeFiles/matio.dir/src/matvar_cell.c.obj CMakeFiles/matio.dir/src/matvar_struct.c.obj CMakeFiles/matio.dir/src/mat4.c.obj CMakeFiles/matio.dir/src/mat5.c.obj CMakeFiles/matio.dir/src/snprintf.c.obj CMakeFiles/matio.dir/src/read_data.c.obj CMakeFiles/matio.dir/visual_studio/matio.rc.obj

CMakeFiles/matdump.dir/includes_C.rsp:

-ID:/workspace/GitHub/matio/src -isystem C:/Users/kgorur/Anaconda3/Library/include 

CMakeFiles/matdump.dir/linklibs.rsp:

 liblibmatio.dll.a -lm C:/Users/kgorur/Anaconda3/Library/lib/hdf5.lib C:/aroot/stage/Library/lib/z.lib D:/dev/Msys2/mingw64/lib/libz.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 

CMakeFiles/matdump.dir/objects1.rsp:

CMakeFiles/matdump.dir/tools/matdump.c.obj
bkaangorur commented 3 years ago

After I followed your comments, I could understand the problem. The problem was that my Msys2 installation did not have an HDF5 installation. Since Cmake was able to find HDF5 in Anaconda directory, which is already in my environment path, it tried to use that HDF5 libraries during the linkage. So, I installed HDF5 package to MSYS2 and the building is completed with no problems.

Thank you very much for your help.