dropbox / lepton

Lepton is a tool and file format for losslessly compressing JPEGs by an average of 22%.
https://blogs.dropbox.com/tech/2016/07/lepton-image-compression-saving-22-losslessly-from-images-at-15mbs/
Apache License 2.0
5.01k stars 355 forks source link

Compile error in Visual Studio 2015 #109

Closed Kasdision closed 6 years ago

Kasdision commented 6 years ago

When I cmake the lepton into a VC14 project, I want to complile the project, but sadly I got this error:

4>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(39): error C2065: “O_RDONLY”: Undeclared identifier
4>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2065: “O_BINARY”: Undeclared identifier
4>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2660: “open”:Function does not accept 1 parameter
5>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(39): error C2065: “O_RDONLY”: Undeclared identifier
5>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2065: “O_BINARY”: Undeclared identifier
5>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2660: “open”:Function does not accept 1 parameter
3>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(39): error C2065: “O_RDONLY”: Undeclared identifier
3>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2065: “O_BINARY”: Undeclared identifier
3>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2660: “open”:Function does not accept 1 parameter
2>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(39): error C2065: “O_RDONLY”: Undeclared identifier
2>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2065: “O_BINARY”: Undeclared identifier
2>E:\workspace\Image Compression\lepton-master\src\lepton\concat.cc(41): error C2660: “open”:Function does not accept 1 parameter

My Compiler Environment is VS2015(release 64-bit), and I compile the project in win7. Does anyone know what this is about? Can someone help me....

danielrh commented 6 years ago

I think you may be able to fix it by adding an underscore to those identifiers like _O_BINARY and _open I may have a chance to reassert windows compat soon, but another option, for now, is to check out an older version of this codebase--

Kasdision commented 6 years ago

@danielrh Thank you for your reply, I have found that the error is from the file: concat.cc(line 27):

void concatenate_files(int fdint, int fdout) {
    using namespace Sirikata;
    std::vector<IOUtil::FileReader*,
                JpegAllocator<IOUtil::FileReader*>> files_to_concatenate;
    files_to_concatenate.push_back(new IOUtil::FileReader(fdint, 0x7fffffff, false));
    if (fdout == -1) {
        fdout = 1; // push to stdout
    }
    IOUtil::FileWriter writer(fdout, false, false);
    for (const char ** file = filelist + 1; *file != NULL; ++file) {
        int cur_file = open(*file, O_RDONLY
#ifdef _WIN32
                            |O_BINARY
#endif
            );
...................

I have tried to add underscore separately to the open, O_RDONLY and O_BINARY, but I still got the same error as I started with. The compiler still prompt O_RDONLY and O_BINARY are Undeclared identifier. I have also found those two words are define in fcntl.h:

#if !__STDC__
    #define O_RDONLY     _O_RDONLY
    #define O_WRONLY     _O_WRONLY
    #define O_RDWR       _O_RDWR
    #define O_APPEND     _O_APPEND
    #define O_CREAT      _O_CREAT
    #define O_TRUNC      _O_TRUNC
    #define O_EXCL       _O_EXCL
    #define O_TEXT       _O_TEXT
    #define O_BINARY     _O_BINARY
    #define O_RAW        _O_BINARY
    #define O_TEMPORARY  _O_TEMPORARY
    #define O_NOINHERIT  _O_NOINHERIT
    #define O_SEQUENTIAL _O_SEQUENTIAL
    #define O_RANDOM     _O_RANDOM
#endif

and the actual value is also define in this head file: #define _O_RDONLY 0x0000 // open for reading only #define _O_BINARY 0x8000 // file mode is binary (untranslated) So I just replace O_RDONLY and O_BINARY with 0x0000 and 0x8000. Unfortunately, some other errors have appeared:

8>recoder.obj : error LNK2019: unresolved external symbol "int hdrs" (?hdrs@@3HA) referenced in function "unsigned int __cdecl handle_initial_segments(class bounded_iostream * const)" (?handle_initial_segments@@YAIQEAVbounded_iostream@@@Z)
8>E:\workspace\Image Compression\Build\Release\lepton-avx.exe : fatal error LNK1120: 1 unresolved externals
7>recoder.obj : error LNK2019: unresolved external symbol "int hdrs" (?hdrs@@3HA) referenced in function "unsigned int __cdecl handle_initial_segments(class bounded_iostream * const)" (?handle_initial_segments@@YAIQEAVbounded_iostream@@@Z)
7>E:\workspace\Image Compression\Build\Release\lepton.exe : fatal error LNK1120: 1 unresolved externals
9>recoder.obj : error LNK2019: unresolved external symbol "int hdrs" (?hdrs@@3HA) referenced in function "unsigned int __cdecl handle_initial_segments(class bounded_iostream * const)" (?handle_initial_segments@@YAIQEAVbounded_iostream@@@Z)
9>E:\workspace\Image Compression\Build\Release\lepton-scalar.exe : fatal error LNK1120: 1 unresolved externals
10>recoder.obj : error LNK2019: unresolved external symbol "int hdrs" (?hdrs@@3HA) referenced in function "unsigned int __cdecl handle_initial_segments(class bounded_iostream * const)" (?handle_initial_segments@@YAIQEAVbounded_iostream@@@Z)
danielrh commented 6 years ago

Should be fixed on master: can you try?