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

Fix file opening on windows #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

lovasoa
Copy link
Contributor

@lovasoa lovasoa commented Sep 10, 2023

Today, I received the following email:

I'm just a hobbyist programmer, lacking the knowledge to properly join the github community. But you were the last to work on it, so here's a patch:

decode.cc
std::ifstream in_file(argv[1]);
to
std::ifstream in_file(argv[1], std::ifstream::binary);

There. Now the thing can cross-compile to Windows with mingw. Not explicitly specifying the file should open in binary was fine on linux. On windows the file opened but couldn't be read correctly.

I did finally get the thing to run on Windows. Only took me four hours learning new and ever-more-obscure compiler flags. I'm annoyed and haven't got enough tea in me, so I'll be less rude later.

Vyl Bird


I'm just transmitting the patch so that it isn't lost.

Today, I received the following email: 

I'm just a hobbyist programmer, lacking the knowledge to properly join the github community. But you were the last to work on it, so here's a patch:

decode.cc
std::ifstream in_file(argv[1]);
to
std::ifstream in_file(argv[1], std::ifstream::binary);

There. Now the thing can cross-compile to Windows with mingw. Not explicitly specifying the file should open in binary was fine on linux. On windows the file opened but couldn't be read correctly.

I did finally get the thing to run on Windows. Only took me four hours learning new and ever-more-obscure compiler flags. I'm annoyed and haven't got enough tea in me, so I'll be less rude later.

Vyl Bird
---


I'm just transmitting the patch so that it isn't lost.
@lovasoa lovasoa changed the title Always open input file as binary Fix file opening on windows Sep 10, 2023
@codeburd
Copy link

Ah, got the old account password dug up! Ok, Windows portability. The code itsself is fine, aside from the aforementioned critical-but-easily-fixed bug. The problem is just the build process - bazel might be rather overkill for this application. Knusperli is small, and doesn't need such an elaborate build tool. You can cross-compile it for Windows, but you have to change a load of compiler flags to deal with the various libraries and such. But, short version:

x86_64-w64-mingw32-g++ -o knusperli -Wl,-S -Wl,-no-as-needed -pass-exit-codes -lm decode.cc jpeg_data_decoder.cc jpeg_data_reader.cc jpeg_huffman_decode.cc output_image.cc dct_double.cc gamma_correct.cc idct.cc preprocess_downsample.cc quantize.cc jpeg_data.cc lodepng.cc -fstack-protector -static-libgcc -static-libstdc++

Notice that there's no need to compile each file to a .a one at a time and then link them all together, as bazel does. Also you have to add lodepng. If you don't include those two libs as static then it will compile, but it won't run.

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

Successfully merging this pull request may close these issues.

2 participants