s-macke/jor1k

Does it support C++(CPP)?

alexwenbj opened this issue · 16 comments

It is a great tool for the educators to teach kids. I dont know is it support the C++ language?Thank you.

It includes gcc (with g++), I think it was gcc 4.9.1. You can compile c++ software in the jor1k emulator, however large projects may run into compilation issues due to the low amount of memory jor1k runs with by default (32mb.)

You can run jor1k locally and change the amount of memory it uses, to allow larger files to compile, though it will be slow.

Another option is to cross compile. This involves using a version of gcc that outputs files in OpenRISC format. Search for openrisc cross compiler or see the repository I created. This would let you compile software that runs on jor1k, and I use this method often for writing my own software that runs on jor1k.

Hope this helps.

@andrakis Thank you very much,I will have a try.

@andrakis It seems it is not support CPP well,for example,I can't use the iostream lib:
#include <iostream>
will cause an error:iostream:No such file or directory.

Are you using g++ to compile? gcc can compile c++ code, but you'll need extra switches. g++ file.cpp -o app would compile a file named "file.cpp" and output a file named "app".

If you're still having trouble, please post the command you're using to compile and I can help you out further.

@andrakis What I did is in this platform:http://s-macke.github.io/jor1k/demos/compile.html,and just add the #include <iostream> in the sample file,then use the gcc to compile and run it.

@alexwenbj that demo saves to a file with a .c extension, so gcc compiles it as a c file. Below the code, you can specify gcc command line options (by default it has -Wall). If you add -x cpp to that it should compile in cpp mode. Another option to try is -lstdc++.

This is more a missed feature of the demo page, that it doesn't have an option for g++ mode. Wouldn't be hard to add, since all the required software is already there if I recall correctly.

@andrakis Thank you for your kindness.But if I add -x cpp to the command options, it told me cpp language not recognized.
As @gbraad said, maybe because of this image not support this feature?If I want to create my own image,where can I start from?

Apologies, the correct option is -x c++ -lstdc++. This is what I get for reading stackoverflow answers and not testing if they're correct because I was on mobile. That demo page works with C++ using that option.

Due to the way gcc is currently being invoked, -lstdc++ is also required. g++ also exists on that filesystem (try running g++ on the terminal to the left), so it would be a simple matter of some changes to compile.html to get a more user-friendly g++ option implemented.

@andrakis It works.Thank you.
@gbraad OK, thank you.

The toolchain build instructions can be found in this repository though the instructions are somewhat out of date.

I ended up finding a copy of the toolchain for cross compiling (which I mirrored) so I could compile on x86_64. Theoretically you could compile a more modern gcc suite (since the demo page is running 4.9.1, a rather old version.)

This is all acedemic, as g++ and all the other needed files are present on this demo anyway. It's just not as straightforward to use in the demo as it could be.

Thank you. @andrakis & @gbraad

@gbraad Yeah,I know. Because I am teaching the junior school students to learn C++,and it is easily&convenient for them to compile and run their code in browser——just launch the browser and do it.So it is meaningful for me to use this online compile.