thorfdbg / libjpeg

A complete implementation of 10918-1 (JPEG) coming from jpeg.org (the ISO group) with extensions for HDR, lossless and alpha channel coding standardized as ISO/IEC 18477 (JPEG XT).
327 stars 81 forks source link

Guidance for building on Windows #21

Closed SimonBiggs closed 4 years ago

SimonBiggs commented 4 years ago

Hi @thorfdbg,

I am attempting to support decoding of 1993 lossless JPEG natively on Windows and I cannot seem to find a compiled executable anywhere.

I have successfully compiled this library within Windows Services for Linux by doing the following:

git clone https://github.com/thorfdbg/libjpeg.git
cd libjpeg
./configure --prefix=/path/to/build-dir
make -j4
make install

This then allows me to successfully use the jpeg executable installed within ~/bin/wavelet/jpeg.

Nevertheless, I would like to distribute this functionality to other PCs through my Medical Physics Python library, PyMedPhys and requesting they set up Windows Services for Linux is unfortunately not viable. I have been attempting to compile this library within MSYS2. I have done this by downloading msys2 from http://www.msys2.org/ and then using pacman to install a range of tools that appear necessary.

Nevertheless, after all of that running:

./configure --prefix=/path/to/build-dir
make -j4

presents me with the following error:

Linking...
C:/Users/sbiggs/AppData/Local/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lc
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile:143: link] Error 1
make: *** [Makefile:200: debug] Error 2

Any direction or nudge in the right direction would be massively appreciated.

I have also attempted using VS2013 with the provided vs12.0/jpeg/jpeg.sln file on a Windows 10 machine. When doing that I get the following errors:

Error   5   error LNK2019: unresolved external symbol "public: __thiscall CositedUpsampler<1,1>::CositedUpsampler<1,1>(class Environ *,unsigned long,unsigned long)" (??0?$CositedUpsampler@$00$00@@QAE@PAVEnviron@@KK@Z) referenced in function "public: static class UpsamplerBase * __cdecl UpsamplerBase::CreateUpsampler(class Environ *,int,int,unsigned long,unsigned long,bool)" (?CreateUpsampler@UpsamplerBase@@SAPAV1@PAVEnviron@@HHKK_N@Z)  C:\Users\sbiggs\git\libjpeg\vs12.0\jpeg\jpeg\jpeglib.lib(upsamplerbase.obj) jpeg

Error   23  error LNK2019: unresolved external symbol "public: __thiscall InterDownsampler<3,1>::InterDownsampler<3,1>(class Environ *,unsigned long,unsigned long)" (??0?$InterDownsampler@$02$00@@QAE@PAVEnviron@@KK@Z) referenced in function "public: static class DownsamplerBase * __cdecl DownsamplerBase::CreateDownsampler(class Environ *,int,int,unsigned long,unsigned long,bool)" (?CreateDownsampler@DownsamplerBase@@SAPAV1@PAVEnviron@@HHKK_N@Z)    C:\Users\sbiggs\git\libjpeg\vs12.0\jpeg\jpeg\jpeglib.lib(downsamplerbase.obj)   jpeg

Error   37  error LNK1120: 32 unresolved externals  C:\Users\sbiggs\git\libjpeg\vs12.0\jpeg\Debug\jpeg.exe  jpeg

Cheers, Simon


For reference I have pasted the full output of the ./configure command below.

sbiggs@RCCC-Physics3 MINGW64 /c/Users/sbiggs/git/libjpeg
$ ./configure --prefix=/c/Users/sbiggs/git/libjpeg-build
configure: loading site script /mingw64/etc/config.site
checking for g++-4.9... no
checking for g++-4.7... no
checking for g++-4.4... no
checking for g++-4.3... no
checking for g++-4.2... no
checking for g++-4.1... no
checking for g++-4.0... no
checking for g++-3.4... no
checking for g++-3.3... no
checking for g++-3.2... no
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for gcc-4.9... no
checking for gcc-4.7... no
checking for gcc-4.4... no
checking for gcc-4.3... no
checking for gcc-4.2... no
checking for gcc-4.1... no
checking for gcc-4.0... no
checking for gcc-3.4... no
checking for gcc-3.3... no
checking for gcc-3.2... no
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... none needed
checking for gcc option to accept ISO Standard C... (cached) none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking for long long... yes
checking for unsigned long long... yes
checking for __int64... yes
checking size of char... 1
checking size of short... 2
checking size of int... 4
checking size of long... 4
checking size of long long... 8
checking size of __int64... 8
checking size of void *... 8
checking for ANSI C header files... (cached) yes
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for size_t... yes
checking whether time.h and sys/time.h may both be included... yes
checking whether stat file-mode macros are broken... no
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking signal.h usability... yes
checking signal.h presence... yes
checking for signal.h... yes
checking for unistd.h... (cached) yes
checking stdarg.h usability... yes
checking stdarg.h presence... yes
checking for stdarg.h... yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking bstring.h usability... no
checking bstring.h presence... no
checking for bstring.h... no
checking bstrings.h usability... no
checking bstrings.h presence... no
checking for bstrings.h... no
checking ctype.h usability... yes
checking ctype.h presence... yes
checking for ctype.h... yes
checking setjmp.h usability... yes
checking setjmp.h presence... yes
checking for setjmp.h... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking time.h usability... yes
checking time.h presence... yes
checking for time.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/times.h usability... no
checking sys/times.h presence... no
checking for sys/times.h... no
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking assert.h usability... yes
checking assert.h presence... yes
checking for assert.h... yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking netinet/in.h usability... no
checking netinet/in.h presence... no
checking for netinet/in.h... no
checking for stdint.h... (cached) yes
checking for int8_t... yes
checking for int16_t... yes
checking for int32_t... yes
checking for int64_t... yes
checking for uint8_t... yes
checking for uint16_t... yes
checking for uint32_t... yes
checking for uint64_t... yes
checking for error_at_line... no
checking whether gcc needs -traditional... no
checking for working memcmp... yes
checking return type of signal handlers... void
checking for vprintf... yes
checking for _doprnt... no
checking for gettimeofday... yes
checking for memchr... yes
checking for memmove... yes
checking for memset... yes
checking for strchr... yes
checking for strerror... yes
checking for strrchr... yes
checking for strtol... yes
checking for strtod... yes
checking for time... yes
checking for snprintf... yes
checking for vsnprintf... yes
checking for clock... yes
checking for gettimeofday... (cached) yes
checking for isspace... yes
checking for longjmp... yes
checking for malloc... yes
checking for free... yes
checking for open... yes
checking for close... yes
checking for read... yes
checking for write... yes
checking for lseek... yes
checking for rename... yes
checking for signal... yes
checking for sleep... yes
checking for fopen64... yes
checking for __builtin_memset... yes
checking for __builtin_memcpy... yes
checking for __builtin_memmove... yes
checking for __builtin_expect... yes
checking for llseek... no
checking for lseek64... yes
checking for htonl... no
checking for htons... no
checking for ntohl... no
checking for ntohs... no
checking for signal... (cached) yes
checking for sigaction... no
checking for sigemptyset... no
checking for pipe... no
checking for dup... yes
checking for dup2... yes
checking for execve... yes
checking for fork... no
checking for fstat... yes
checking for system... yes
checking for kill... no
checking for sleep... (cached) yes
checking for struct timeval... no
checking for ptrdiff_t... yes
checking for sysconf... no
checking for times... no
checking for struct tms... no
checking whether _SC_CLK_TCK is declared... no
checking whether CLK_TCK is declared... yes
checking whether HZ is declared... no
checking whether STDIN_FILENO is declared... yes
checking whether STDOUT_FILENO is declared... yes
checking whether STDERR_FILENO is declared... yes
checking for library containing exp... none required
checking for __muldc3 in -lgcc_s... yes
checking whether argument type for signal handlers is "int"... yes
checking whether argument type for signal handlers is "..."... no
checking whether the GNU __attribute__ extension is available... yes
checking for the __null keyword... yes
checking whether integer constants are valid template arguments... yes
checking for SIGSEGV and SIGILL signals... yes
checking for atomic arithmetic functions __sync_add_and_fetch and __sync_fetch_and_sub... yes
checking for atomic __sync_val_compare_and_swap... yes
checking for worst-case structural alignment... 4
checking whether private subclasses have access to private members... yes
checking whether templates are in local namespace... yes
checking whether initializers of static const integral members work... yes
checking whether casting works in template arguments... yes
checking whether the noreturn attribute is available... yes
checking whether the always_inline attribute is available... no
checking whether __attribute__((visibility("hidden"))) is available for types... no
checking whether __attribute__((visibility("internal"))) is available for types... yes
checking whether __attribute__((visibility("default"))) is available for types... yes
checking whether __attribute__((may_alias)) is available for types... yes
checking whether __attribute__((aligned)) is available for types... yes
checking for working const_cast<> capability... yes
checking for working reinterpret_cast<> capability... yes
checking for uniqueness of static members thru various derivation paths... yes
checking whether __restrict__ pointers are available... yes
checking for the -mfpmath=387 compiler switch... yes
checking for the -fvisibility=internal compiler switch... yes
checking for the -fPIC compiler switch... yes
configure: creating ./config.status
config.status: creating automakefile
config.status: creating autoconfig.h
SimonBiggs commented 4 years ago

I solved my own problem! :) ... after much trial and error.

I installed Visual Studio Code 2013, opened up the solution file at vs12.0/jpeg/jpeg.sln and then set the following:

Project > Properties > Configuration Properties > Linker > General > Force File Output set this to Undefined Symbol Only (/FORCE:UNRESOLVED). This was as per the guidance found at https://stackoverflow.com/a/2326554/3912576.

This produced jpeg.exe. For others to easily access it I have uploaded this executable to https://zenodo.org/record/3592182#.XgGeVUczZhE along with the source code.

scaramallion commented 4 years ago

The alternative if you're using MSYS2 is to change from -lc to -lmsvcrt in Makefile_Settings.gcc:

LDLIBS      = -lmsvcrt -lm $(EXTRA_LIBS) #gcc_s required for long division/multiplication on 32bit