XboxDev / nxdk-libcxx

Copy of libcxx git repository located at http://llvm.org/git/libcxx (adapted for original Xbox / nxdk toolchain)
http://libcxx.llvm.org
Other
4 stars 3 forks source link

error: no member named 'cout' in namespace 'std' #5

Open JayFoxRox opened 3 years ago

JayFoxRox commented 3 years ago

While getting rid of my old GitHub notifications I noticed that I had an issue with lack of std::cout in the past, which became a problem while porting some projects.

This issue is basically a bug report for the workaround seen here: https://github.com/JayFoxRox/nxdk/tree/2c850026a565eea0435cb14370b0a9d8864cdd33/usr/share/nxdk/samples/ozz-animation (I also briefly looked at the independent issue with #include <atomic> / std::atomic_int allocation_count_ / allocation_count_.store(0) / allocation_count_.load(), which appears to have been a problem back then, but it seems to be compile fine on https://github.com/XboxDev/nxdk/commit/72485f402b7f2b486430af9236a26fdef5ef7bd7 / https://github.com/XboxDev/nxdk-libcxx/commit/c594e975f383418d98dbdf35a8f2fff4699a62fb. I did not try running it though)

#include <hal/video.h>
#include <windows.h>

#include <iostream>

int main(void) {
  XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);

  std::cout << "Hello!" << std::endl; // Does not compile: "error: no member named 'cout' in namespace 'std'"
  std::cerr << "Hello!" << std::endl; // Compiles

  while (true) {
    Sleep(2000);
  }

  return 0;
}

Not sure if we had discussed this in the past or if an issue already exists.

JayFoxRox commented 3 years ago

This will be caused by this:

https://github.com/XboxDev/nxdk-libcxx/blob/c594e975f383418d98dbdf35a8f2fff4699a62fb/include/__config#L18-L19

which controls this:

https://github.com/XboxDev/nxdk-libcxx/blob/c594e975f383418d98dbdf35a8f2fff4699a62fb/include/iostream#L48-L59

I think that disabling cout is pointless, if there are also cerr and clog, which also go nowhere. The nxdk libc also provides stdout (and stdin), so I don't think there's a good reason to disable it in C++.

With stdout / cout we can probably just ignore it. For stdin / cin we'll need a better solution probably.

nxdk will probably need a way to hook up virtual file descriptors for pdclib to handle this properly. I assume it's possible to register a virtual filesystem through the kernel? If that works, we could optionally connect stdout / stdin to debuggers via network (or similar).

Edit: Here are some links in how this works on Windows: