Unable to include iostream, fstream or sstream

Bug #1247336 reported by Edward Bart
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cheerp
Fix Released
Medium
Unassigned

Bug Description

When I try to incluse iostream, fstream or sstream I got the following errors:

s $ /opt/duetto/bin/clang -Os -std=c++11 -S -target duetto HelloClient.cpp -o HelloClient.js
In file included from HelloClient.cpp:5:
In file included from /opt/duetto/include/c++/v1/iostream:38:
In file included from /opt/duetto/include/c++/v1/ios:216:
In file included from /opt/duetto/include/c++/v1/__locale:18:
In file included from /opt/duetto/include/c++/v1/mutex:176:
In file included from /opt/duetto/include/c++/v1/__mutex_base:15:
In file included from /opt/duetto/include/c++/v1/chrono:268:
/opt/duetto/include/c++/v1/ratio:256:20: error: integer constant is larger than the largest unsigned integer type
typedef ratio<1LL, 1000000000000000000LL> atto;
                   ^
/opt/duetto/include/c++/v1/ratio:257:23: error: integer constant is larger than the largest unsigned integer type
typedef ratio<1LL, 1000000000000000LL> femto;
                      ^
/opt/duetto/include/c++/v1/ratio:258:26: error: integer constant is larger than the largest unsigned integer type
typedef ratio<1LL, 1000000000000LL> pico;
                         ^
/opt/duetto/include/c++/v1/ratio:269:21: error: integer constant is larger than the largest unsigned integer type
typedef ratio< 1000000000000LL, 1LL> tera;
                    ^
/opt/duetto/include/c++/v1/ratio:270:18: error: integer constant is larger than the largest unsigned integer type
typedef ratio< 1000000000000000LL, 1LL> peta;
                 ^
/opt/duetto/include/c++/v1/ratio:271:15: error: integer constant is larger than the largest unsigned integer type
typedef ratio<1000000000000000000LL, 1LL> exa;
              ^
In file included from HelloClient.cpp:5:
In file included from /opt/duetto/include/c++/v1/iostream:38:
In file included from /opt/duetto/include/c++/v1/ios:216:
In file included from /opt/duetto/include/c++/v1/__locale:18:
In file included from /opt/duetto/include/c++/v1/mutex:176:
/opt/duetto/include/c++/v1/__mutex_base:37:5: error: unknown type name 'pthread_mutex_t'
    pthread_mutex_t __m_;
    ^
/opt/duetto/include/c++/v1/__mutex_base:57:13: error: unknown type name 'pthread_mutex_t'
    typedef pthread_mutex_t* native_handle_type;
            ^
/opt/duetto/include/c++/v1/__mutex_base:42:41: error: use of undeclared identifier 'PTHREAD_MUTEX_INITIALIZER'
     constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
                                        ^
/opt/duetto/include/c++/v1/__mutex_base:304:5: error: unknown type name 'pthread_cond_t'
    pthread_cond_t __cv_;
    ^
/opt/duetto/include/c++/v1/__mutex_base:348:13: error: unknown type name 'pthread_cond_t'
    typedef pthread_cond_t* native_handle_type;
            ^
/opt/duetto/include/c++/v1/__mutex_base:308:44: error: use of undeclared identifier 'PTHREAD_COND_INITIALIZER'
    constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}
                                           ^
In file included from HelloClient.cpp:5:
In file included from /opt/duetto/include/c++/v1/iostream:38:
In file included from /opt/duetto/include/c++/v1/ios:216:
In file included from /opt/duetto/include/c++/v1/__locale:18:
/opt/duetto/include/c++/v1/mutex:192:5: error: unknown type name 'pthread_mutex_t'
    pthread_mutex_t __m_;
    ^
/opt/duetto/include/c++/v1/mutex:207:13: error: unknown type name 'pthread_mutex_t'
    typedef pthread_mutex_t* native_handle_type;
            ^
/opt/duetto/include/c++/v1/mutex:259:5: error: unknown type name 'pthread_t'
    pthread_t __id_;
    ^
/opt/duetto/include/c++/v1/mutex:285:5: error: unknown type name 'pthread_t'
    pthread_t __id = pthread_self();
    ^
/opt/duetto/include/c++/v1/mutex:285:22: error: use of undeclared identifier 'pthread_self'
    pthread_t __id = pthread_self();
                     ^
/opt/duetto/include/c++/v1/mutex:359:9: error: use of undeclared identifier 'sched_yield'
        sched_yield();
        ^
/opt/duetto/include/c++/v1/mutex:368:9: error: use of undeclared identifier 'sched_yield'
        sched_yield();
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

Those headers are not been ported yet. Still they are not very useful since there is no filesystem in the browser. stringstream can be still useful though so this will be fixed

Changed in duetto:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

Also, does the compiler crashes? There is an old bug report about a crash after using fstream which I think might be fixed now

Revision history for this message
Edward Bart (edub4rt) wrote :

The compiler doesn't crash for me, I use linux, the other report with the crash when including those headers was from a windows user.

Revision history for this message
Edward Bart (edub4rt) wrote :

Both fstream and iostream are useful too. You said that there is no filesystem in the browser, however I need to open files in C++ to load data like scripts, textures, configs, etc. Duetto have to workout this somehow like via http requests or preloading files into the scripts.

About iostream, it is useful for printing information for debugging purposes with std::cout, for instance I tried using printf from cstdio just to see what would happen and it did nothing, I got no output in my javascript debugger from firefox or chrome, I think that should me implemented too.

Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

C-style stdout/stderr will be supported soon and will print in the browser console. About file access we don't believe it's a good idea to provide a fake implementation of a filesystem on top of http requests. You can actually use XMLHttpRequest to load the data you need. Textures should be loaded using HTMLImageElement as the browser will automatically handle decompression in such case.

You can take a look a the source code for the nontetris demo (https://github.com/ddiproietto/nontetris) as it implements a possible solution to load both text data and images from the server. Most relevant code is here https://github.com/ddiproietto/nontetris/blob/master/src/fileloader.h

Revision history for this message
Artem (artemciy) wrote :

I think the fstream code should compile but at runtime should fail to open any files since there's no filesystem so that the existing code could work and fail gracefully when run on the client.

Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

I don't think that pretending would be actually helpful for the user. Even if it would make it easier to build a project using duetto, then the user would need to track errors at runtime. On the other hand if fstream is completely not supported the user will be notified by the compiler on each use. I think that the point should not be to build a C++ project without modification, but building a C++ project that actually works with minimal modifications.

Changed in cheerp:
status: Confirmed → Fix Committed
Changed in cheerp:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.