Search code examples
cmakemingwnokiaheif

Can't build Nokia HEIF library with make


I'm trying to build the HEIF library in https://github.com/nokiatech/heif, but I'm having no luck.

I have CMake and the latest version of MinGW installed. I'm following the steps to build the library but I'm getting an error.

The first step, which is this:

cd heif/build
cmake --help
cmake ../srcs -G"<Generator listed by above command for your target platform>"

works, but the second step, which is this:

cmake --build .

seems to be working but when it gets to 41% done I get this error:

C:\Users\dantelo\Documents\heif-master\srcs\reader\heifstreamfile.cpp: In constructor 'HEIF::FileStream::FileStream(const char*)':
C:\Users\dantelo\Documents\heif-master\srcs\reader\heifstreamfile.cpp:44:9: error: 'fopen_s' was not declared in this scope
     fopen_s(&m_file, filename, "rb");
     ^~~~~~~
C:\Users\dantelo\Documents\heif-master\srcs\reader\heifstreamfile.cpp:44:9: note: suggested alternative: 'fopen'
     fopen_s(&m_file, filename, "rb");
     ^~~~~~~
     fopen
reader\CMakeFiles\heif_static.dir\build.make:93: recipe for target 'reader/CMakeFiles/heif_static.dir/heifstreamfile.cpp.obj' failed
mingw32-make.exe[2]: *** [reader/CMakeFiles/heif_static.dir/heifstreamfile.cpp.obj] Error 1
mingw32-make.exe[2]: Leaving directory 'C:/Users/dantelo/Documents/heif-master/build'
CMakeFiles\Makefile2:233: recipe for target 'reader/CMakeFiles/heif_static.dir/all' failed
mingw32-make.exe[1]: *** [reader/CMakeFiles/heif_static.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/dantelo/Documents/heif-master/build'
Makefile:85: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

I'm on Windows 10 in case that's relevant. I have no idea why this is happening. Any help appreciated


Solution

  • It seems that fopen_s is only present in the C library provided by Microsoft, i.e. in MSVC. Source: Is there a way to use fopen_s() with GCC or at least create a #define about it?

    Your best bet is then switching to MSVC, because the code you have was apparently never tested with MinGW, as it cannot be compiled by the latter.

    Alternatively, if you are feeling lucky, you can just use some #define tricks to convert fopen_s to the standard fopen (see the answers in the linked question) and hope that this is the only incompatibility in the code.