Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am looking for a c++ compiler that I can integrate into a page from my website. It means that a user could write and compile c++ code on the website.

What I have tried:

Until now, I've found that I can do this using "repl.it"(https://docs.replit.com/hosting/embedding-repls), but the user needs to log in before writing any code. Also, I found a cool way to do this without logging in, but it's only working with python (https://trinket.io). :/

I also tried jDoodle, but the user can't edit the code on my website.

Do you know a similar method to integrate an embedded compiler like "repl.it" or "trinket", which works with c++?
Posted
Updated 9-Dec-21 7:08am
v3

The GDB compiler / debugger works, as is shown on their online compiler site: Online C Compiler - online editor[^] - and it works for loads of languages!

Be aware though that you are running one heck of a risk if you aren't careful: part of the reason Javascript is so limited is to prevent malware running on client computers. What you are proposing would allow client malware to run on your server ... not a nice thought.
 
Share this answer
 
v2
You can use just about any C compiler you want. I haven't seen one yet that isn't command-line driven.

Like 'Griff said, you better be DAMN careful about how you compile code from an untrusted user and even more careful about the account you use to execute the resulting code. Use a very limited account configured specifically for the purpose so as to not have your web server destroyed by a malicious user.

You also have to keep track of how long you allow the resulting code to run. You don't want someone getting process after process into an infinite loop and eventually crashing your server because of resources.

If I were to do this, I would probably set a virtual machine server where code is submitted to a running VM, compiled on it, and executed. Once the done and the result picked up by the web server, destroy the VM and rebuild another one from a template.

This is not as simple a thing as you would expect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900