s-macke / jor1k

Online OR1K Emulator running Linux
http://jor1k.com
BSD 2-Clause "Simplified" License
1.73k stars 193 forks source link

Does it support C++(CPP)? #148

Closed alexwenbj closed 4 years ago

alexwenbj commented 4 years ago

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

andrakis commented 4 years ago

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.

alexwenbj commented 4 years ago

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

alexwenbj commented 4 years ago

@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.

andrakis commented 4 years ago

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.

gbraad commented 4 years ago

this is unrelated to the emulator, but rather about the image that is provided. please consider recreating the image to include the components you want.

On Tue, Oct 29, 2019 at 11:59 AM Julian Thatcher notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/s-macke/jor1k/issues/148?email_source=notifications&email_token=AAAAOZSS3ZCR2RD4ITKBVRLQQ6YLNA5CNFSM4JFWDH5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECPE7KI#issuecomment-547245993, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAOZVU7XYYPWN6YMD6BRDQQ6YLNANCNFSM4JFWDH5A .

--

Gerard Braad | http://gbraad.nl [ Doing Open Source Matters ]

alexwenbj commented 4 years ago

@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.

andrakis commented 4 years ago

@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.

alexwenbj commented 4 years ago

@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?

andrakis commented 4 years ago

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.

gbraad commented 4 years ago

The image was created using the OpenRISC toolchain. This is a procedure that might be described somewhere in the docs or else somewhere on one of the help pages related to OR1K. I do not remember well, as it has been a long time ago.

alexwenbj commented 4 years ago

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

andrakis commented 4 years ago

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.

gbraad commented 4 years ago

It's just not as straightforward to use in the demo as it could be.

hence it being a demo. We never expect someone to use this for serious development. ;-)

On Tue, Oct 29, 2019 at 8:53 PM Julian Thatcher notifications@github.com wrote:

The toolchain build instructions can be found in this repository https://github.com/s-macke/jor1k-toolchain-builder though the instructions are somewhat out of date.

I ended up finding a copy of the toolchain for cross compiling (which I mirrored https://github.com/andrakis/openrisc-toolchain) 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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/s-macke/jor1k/issues/148?email_source=notifications&email_token=AAAAOZUMSMDOTK6HDZMPMFDQRAW3TA5CNFSM4JFWDH5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECQLVVQ#issuecomment-547404502, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAOZSARUJMQJYL3BKYXQTQRAW3TANCNFSM4JFWDH5A .

--

Gerard Braad | http://gbraad.nl [ Doing Open Source Matters ]

alexwenbj commented 4 years ago

Thank you. @andrakis & @gbraad

gbraad commented 4 years ago

I liken this to running an Amiga emulator and relive the ye olde days of yore and run an obsolete C compiler like Dice to get your old demo code compiled again, or trying to open RTF-formatted files to read a document, or failing to interact with the average website Aweb or iBrowse just don't parse the javascript or css. It is great fun, you betcha! but I wouldn't want to do this exercise for more than an hour on end. Use the actual development suite instead... you will be much more productive.

alexwenbj commented 4 years ago

@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.