Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to get static binaries? #1

Open
Dingo64 opened this issue May 20, 2017 · 30 comments
Open

Possible to get static binaries? #1

Dingo64 opened this issue May 20, 2017 · 30 comments

Comments

@Dingo64
Copy link

Dingo64 commented May 20, 2017

I installed libpng and libjpeg on my system. Compiled resdet but it still doesn't work with jpegs. Would it be possible for you to provide static binary for Linux? (Or maybe even for Windows?)

@0x09
Copy link
Owner

0x09 commented May 20, 2017

I was thinking it would be a good idea to host some, so yes I'd like to do this.

But in the mean time, what happens when you try to build with libjpeg support? Could you post the output of ./configure and your distro/version?

@Dingo64
Copy link
Author

Dingo64 commented May 20, 2017

Binaries would be awesome, thanks!

Here's output from my Debian 8.8 Jessie AMD64 of configure:

CC is "/usr/bin/cc"
CFLAGS is "-Ofast -march=native -mtune=native -std=gnu99 "
AR is "/usr/bin/ar"
PREFIX is "/usr/local"
BINPREFIX is "/usr/local/bin"
LIBPREFIX is "/usr/local/lib"
INCPREFIX is "/usr/local/include"
SHAREPREFIX is "/usr/local/share/resdet"
PCPREFIX is "/usr/local/lib/pkgconfig"

Testing for fftw3f... ok
Testing for jpeglib.h... ok
Testing for jpeg... ok
Testing for magic.h... not found
Testing for libpng... ok
Testing for mjpegtools... not found
Testing for MagickWand... not found
Testing for m... ok
Generating lib/resdet.pc

So JPEG and PNG libraries are found. Now output from make:

/usr/bin/cc -o resdet -DHAVE_FFTW -DHAVE_LIBJPEG -DHAVE_LIBPNG -I/usr/include/libpng12  src/resdet.o lib/libresdet.a -ljpeg -lm -lfftw3f -lpng12
/usr/bin/cc -o stat -DHAVE_FFTW -DHAVE_LIBJPEG -DHAVE_LIBPNG -I/usr/include/libpng12  src/stat.o lib/libresdet.a -ljpeg -lm -lfftw3f -lpng12
/usr/bin/cc -o profile -DHAVE_FFTW -DHAVE_LIBJPEG -DHAVE_LIBPNG -I/usr/include/libpng12  src/profile.o lib/libresdet.a -ljpeg -lm -lfftw3f -lpng12

Seems OK to me. And now when I try to analyze a JPEG image:
Invalid image
And that's it. Works fine with PNGs. I don't see a way to read PNG files from stdin with resdet so I have to first convert JPEGs into PNGs, store them and then run resdet. While this method works it's not very handy.

@0x09
Copy link
Owner

0x09 commented May 20, 2017

Thanks, this was actually just a dumb bug in the fallback filetype detection. If you pull and rebuilt it should work.

@Dingo64
Copy link
Author

Dingo64 commented May 20, 2017

I tried to compile it with Cygwin for Windows and while it compiles fine and does "-version":

$ ./resdet -version
Usage: ./resdet -h -m <method> -v <verbosity> image

it doesn't want to work even on PNG images:

$ ./resdet -version TEST2.png
Aborted (core dumped)

Output from configure from Cygwin:

$ ./configure
CC is "/usr/bin/cc"
CFLAGS is "-Ofast -march=native -mtune=native -std=gnu99 "
AR is "/usr/bin/ar"
PREFIX is "/usr/local"
BINPREFIX is "/usr/local/bin"
LIBPREFIX is "/usr/local/lib"
INCPREFIX is "/usr/local/include"
SHAREPREFIX is "/usr/local/share/resdet"
PCPREFIX is "/usr/local/lib/pkgconfig"

Testing for fftw3f... ok
Testing for jpeglib.h... ok
Testing for jpeg... ok
Testing for magic.h... not found
Testing for libpng... ok
Testing for mjpegtools... not found
Testing for MagickWand... not found
Testing for m... ok
Generating lib/resdet.pc

And from make:

/usr/bin/cc -o resdet -DHAVE_FFTW -DHAVE_LIBJPEG -DHAVE_LIBPNG -I/usr/include/libpng16 src/resdet.o lib/libresdet.a -ljpeg -lm -lfftw3f -lpng16
/usr/bin/cc -o stat -DHAVE_FFTW -DHAVE_LIBJPEG -DHAVE_LIBPNG -I/usr/include/libpng16 src/stat.o lib/libresdet.a -ljpeg -lm -lfftw3f -lpng16
/usr/bin/cc -o profile -DHAVE_FFTW -DHAVE_LIBJPEG -DHAVE_LIBPNG -I/usr/include/libpng16 src/profile.o lib/libresdet.a -ljpeg -lm -lfftw3f -lpng16

If you ever consider to make a Windows build perhaps this will be helpful. Anyway- thanks for a nice tool!

@Dingo64
Copy link
Author

Dingo64 commented May 20, 2017

I grabbed new code and it works great under Debian 8.8 with JPEGs! Great job! Thank you!

@0x09
Copy link
Owner

0x09 commented May 20, 2017

Good to hear, I'll leave this open while I investigate setting up cross platform builds. The code should all be standard C, so building for Windows natively with mingw or clang rather than cygwin should be possible. But I haven't tested this in a long time.

@Dingo64
Copy link
Author

Dingo64 commented May 20, 2017

Digital Mars C Compiler for Windows says:

dmc src/resdet.c -Iinclude/ -Ilib/
Error C:\\dm\bin\..\include\unistd.h 6:  "unistd.h is not
for Windows use"
--- errorlevel 1

@0x09
Copy link
Owner

0x09 commented May 20, 2017

Oh yeah, this is used in the tools for command line option parsing. I was thinking more about the library code. But I'll look into it. There isn't anything inherently platform dependent about the project.

@Dingo64
Copy link
Author

Dingo64 commented May 20, 2017

I think I am quite close to compile it on Debian for Win32:

# i686-w64-mingw32-gcc -std=c11  src/resdet.c -Iinclude/ -Ilib/ -Ilib/kissfft
/tmp/ccfVDSmh.o:resdet.c:(.text+0x7d): undefined reference to `resdet_methods'
/tmp/ccfVDSmh.o:resdet.c:(.text+0x1bc): undefined reference to `resdet_open_context'
/tmp/ccfVDSmh.o:resdet.c:(.text+0x205): undefined reference to `resdet_get_method'
/tmp/ccfVDSmh.o:resdet.c:(.text+0x23d): undefined reference to `resdetect_file'
/tmp/ccfVDSmh.o:resdet.c:(.text+0x24d): undefined reference to `resdet_close_context'

@NaruZosa
Copy link

Hi, just wondering if there's still plans for cross platform support and static binaries?

@0x09
Copy link
Owner

0x09 commented Sep 23, 2018

@BradleyDS2 I was able to compile without issue using MSYS2. The caveat is that this is linked with msys-2.0.dll and so msys will need to be installed (or at least this dll) to run it.
resdet-msys2.zip

This was built using the following config.mak

CC=/usr/bin/cc
AR=/usr/bin/ar
CFLAGS=-Ofast -march=x86-64 -mtune=generic
PREFIX=/usr/local
BINPREFIX=/usr/local/bin
LIBPREFIX=/usr/local/lib
INCPREFIX=/usr/local/include
SHAREPREFIX=/usr/local/share/resdet
PCPREFIX=/usr/local/lib/pkgconfig
DEFS= -DHAVE_LIBJPEG=1 -DHAVE_LIBPNG=1 -I/usr/include/libpng16
LIBS= -lpng16 -lz -ljpeg -static

This can be reproduced using the existing build script simply by installing msys2, then using the included package manager to install gcc, make, and pkg-config (libjpeg and libpng aren't included and need to be compiled separately.)

Builds within the vanilla mingw environment (no msys-2.0.dll dependency) succeed but seem to have issues with read failures within libjpeg/libpng which I haven't yet found an explanation for.

I haven't attempted to port to VS/cl.exe

@NaruZosa
Copy link

Awesome! Are there any plans to add prebuilt binaries to the releases page in future?

@0x09
Copy link
Owner

0x09 commented Sep 24, 2018

Sure, I'll revisit setting up non-msys dependent builds and add an official releases based on that going forward. I haven't made it a priority since activity on this ticket died down, so it's helpful for me to know that there's a real need for this. Thanks!

@NaruZosa
Copy link

That's awesome, thanks a lot!

There's no need for you to thank me though, I wasn't sure if I'd even get a response, so I'm really grateful to you for responding and doing all of this.

@Shad0w1and
Copy link

Hi, I second this idea! It will be so much help if you could put the stable binaries under the release tag. It is such a great tool!

@0x09
Copy link
Owner

0x09 commented Jul 23, 2019

Sorry for the lack of updates here, shortly after the last activity on this ticket my Windows machine was rendered unusable in a flood, effectively putting this on hold. I looked into the alternatives (mingw cross compilation, the auto-expiring dev VMs from Microsoft, just buying another license) but nothing was particularly attractive. I'll have to repair the machine eventually, so I'll update once that happens or a better alternative crops up.

@rogerallen741
Copy link

rogerallen741 commented Feb 17, 2020

Hi all I already install libpng and libjpeg on my system(Ubuntu 16.04). However when I run resdet test.png it got the errors as bellows :

$ resdet test.png
Invalid image

Can you guys give me any advises.
Thanks

@zvezdochiot
Copy link

@0x09 say:

I looked into the alternatives

Interestingly, and under ReactOS (https://reactos.org/), you can compile programs for Windows?

@zvezdochiot
Copy link

zvezdochiot commented Feb 17, 2020

@rogerallen741 say:

Invalid image

Try to test. In:

resdet/lib/resdet.c

Lines 119 to 126 in 20926fb

RDError resdetect(unsigned char* restrict image, size_t nimages, size_t width, size_t height, RDResolution** rw, size_t* cw, RDResolution** rh, size_t* ch, RDMethod* method) {
if(rw) { *rw = NULL; *cw = 0; }
if(rh) { *rh = NULL; *ch = 0; }
if(!method)
return RDEINVAL;
return resdetect_with_params(image,nimages,width,height,rw,cw,rh,ch,method,DEFAULT_RANGE,method->threshold);
}

put another error from:

resdet/include/resdet.h

Lines 32 to 37 in 20926fb

static const char* const RDErrStr[] = {
[RDEOK] = "",
[RDENOMEM] = "Out of memory",
[RDEINTERNAL] = "Internal error",
[RDEINVAL] = "Invalid image"
};

example:

    return RDENOMEM; 

@0x09
Copy link
Owner

0x09 commented Feb 17, 2020

Hi @rogerallen741, can you post your config.mak and the image file?
In case it’s an issue with detecting libpng, resdet has a built-in pgm reader you can try in the mean time which should work.
e.g. with imagemagick’s convert util:

convert test.png test.pgm
./resdet test.pgm

@rogerallen741
Copy link

Hi @zvezdochiot i replaced the RDEINVAL and built again. Also test with same image(test.png), while it output the same results: Invalid image lol...

@rogerallen741
Copy link

Hi @0x09 here is the config.mak

CC=/usr/bin/cc
AR=/usr/bin/ar
CFLAGS=-Ofast -march=native -mtune=native -std=gnu99 
PREFIX=/usr/local
BINPREFIX=/usr/local/bin
LIBPREFIX=/usr/local/lib
INCPREFIX=/usr/local/include
PCPREFIX=/usr/local/lib/pkgconfig
HAVE_FFTW=3
HAVE_LIBJPEG=1
HAVE_LIBPNG=1
DEFS= -DHAVE_LIBJPEG -DHAVE_LIBPNG=1 -I/usr/include/libpng12
LIBS= -ljpeg -lm -lfftw3f -lpng12

Here is the testing image(test.png)
test

I also convert test.png to test.pgm by imagemagick. Here is the results:

*** stack smashing detected ***: resdet terminated
Aborted (core dumped)

@zvezdochiot
Copy link

zvezdochiot commented Feb 17, 2020

@rogerallen741 say:

while it output the same results

A I was hoping so. So still reading the image. To be sure, check a similar replacement in:

resdet/lib/image.c

Lines 78 to 82 in 2d870af

if(reader)
*image = reader->read(filename,width,height,nimages);
return *image ? RDEOK : RDEINVAL;
}

and test.

And add before return:

printf("Mime: %s", c);

@0x09
Copy link
Owner

0x09 commented Feb 17, 2020

lpng12

Ah, this is linking with libpng 1.2 whereas resdet really only targets the current release of 1.6. The configure script definitely should be changed to take this into consideration before treating libpng as "enabled" as it did here. I'm able to process this successfully on debian using libpng16.
If you can't install libpng16 but have access to ImageMagick's MagickWand library, resdet can use that to read everything the png source can + more.

The pgm issue is separate and was fun to track down as it differs by OS/libc, but that's now fixed in 21e2148 -- thanks for finding this.

@zvezdochiot
Copy link

@0x09 say:

this is linking with libpng 1.2 whereas resdet really only targets the current release of 1.6.

$ ldd /usr/bin/resdet
	linux-gate.so.1 =>  (0xb76f2000)
	libresdet.so.0 => /usr/lib/i386-linux-gnu/libresdet.so.0 (0xb76a4000)
	libjpeg.so.8 => /usr/lib/i386-linux-gnu/libjpeg.so.8 (0xb766b000)
	libmagic.so.1 => /usr/lib/i386-linux-gnu/libmagic.so.1 (0xb764a000)
	libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xb7624000)
	libfftw3f.so.3 => /usr/lib/i386-linux-gnu/libfftw3f.so.3 (0xb7427000)
	libpng12.so.0 => /lib/i386-linux-gnu/libpng12.so.0 (0xb73fd000)
	libMagickWand.so.5 => /usr/lib/i386-linux-gnu/libMagickWand.so.5 (0xb72e0000)
	libMagickCore.so.5 => /usr/lib/i386-linux-gnu/libMagickCore.so.5 (0xb7018000)
...

Everything works. Maybe because of imagemagick?

@zvezdochiot
Copy link

zvezdochiot commented Feb 17, 2020

@0x09 say:

resdet really only targets the current release of 1.6

Maybe you should take a closer look at libiio (https://github.com/mnhrdt/iio).

@rogerallen741
Copy link

rogerallen741 commented Feb 17, 2020

@0x09:
You mean resdet(current version) support libpng 1.6 only, so I should install libpng 1.6 instead libpng 1.2 ?

@zvezdochiot:
I add the printf("Mime: %s", c). Here is the results.
Apparently, the code works fine now but i have totally no idea why it can works ....

$ resdet test.png
Mime: image/pnggiven: 474x474
best guess: 316x316
all width        height
  316 (68.93%)     316 (66.46%)
  240 (55.47%)   
  196 (55.01%)   

After i remove the printf(), the code also can work properly.

@zvezdochiot
Copy link

@rogerallen741 say:

so I should install libpng 1.6 instead libpng 1.2 ?

Not instead, but beside. There are many things that depend on libpng 1.2 on the system.

@0x09
Copy link
Owner

0x09 commented Feb 17, 2020

@zvezdochiot thanks for the link, that looks like a neat project.

@rogerallen741 since you do have ImageMagick's libraries installed now you shouldn't actually need to install the newer version of libpng for this and may just want to disable it, since again ImageMagick supports that and far more formats. The libpng image reader is really only provided for instances where ImageMagick is not available.

Also, if you have any further issues or just want to continue discussion please open a new github issue for this as we're potentially sending quite a lot of notifications to folks who were only watching this one for static binary support.

@zvezdochiot
Copy link

zvezdochiot commented Feb 17, 2020

@rogerallen741 say:

After i remove the printf(), the code also can work properly.

Seems understand. Replace:

resdet/include/resdet.h

Lines 25 to 30 in 21e2148

typedef enum RDError {
RDEOK = 0,
RDENOMEM,
RDEINTERNAL,
RDEINVAL
} RDError;

on the:

typedef enum RDError {
	RDEOK = 0,
	RDENOMEM,
	RDEINTERNAL,
	RDEINVAL,
	RDENONE
} RDError;

and return RDEINVAL to:

resdet/lib/image.c

Lines 78 to 82 in 2d870af

if(reader)
*image = reader->read(filename,width,height,nimages);
return *image ? RDEOK : RDEINVAL;
}

@0x09 0x09 mentioned this issue Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants