1

I want to create a program that modifies another c++ source,compiles it and runs the exe. I mean with something like gcc may be I can but on a windows os gcc may not be present. Is it possible?

5
  • What if you pack the compiler as part of your app (in fact it is)... is it feasible? Commented Sep 2, 2010 at 15:14
  • it's possible but I don't like that variant.However it seems the only way on Windows... Commented Sep 2, 2010 at 15:41
  • I think with a platform like Windows, you just can't ensure if a compiler is available, sadly. Commented Sep 2, 2010 at 15:46
  • You can't be sure of having a compiler on *nix either. Commented Sep 2, 2010 at 16:30
  • If your program should be self-contained (in the sense that some Java development environments can produce executables which basically contain a complete java runtime) my gut feeling is that a virtual machine may be the only way to go. Or perhaps you could zip the development environment (libs, headers, preprocessor, compiler, linker) and unpack it on the target as part of the installation. (Seems to be what Helios had in mind too.) Commented Aug 24, 2014 at 3:51

2 Answers 2

2

I think your options are fairly limited for windows:

  1. Check for an install of a compiler (possibly limit this to a short list) and use that compiler
  2. Bring along a compiler in your application's install package
Sign up to request clarification or add additional context in comments.

Comments

2

Cowboy answer:

Only if:

  • the source code doesn't need a lot of files/headers/libraries
  • they can be easily collected by your application
  • the application have connection with some server of yours

The application could:

  • collect the files in a zip
  • send them over the wire to an compiler service (accesible vía HTTP)
  • the server compile it with its own installation
  • and return the binary executable inside the response.

Of course: it depends on so many variables that seems not very feasible. And the zip+http thing could be difficult from a C/C++ app.

4 Comments

hmm it can be slow...and it depends on internet connection. But it's interesting idea ;)
Thanks... anyway I was thinking on it and realized about managing zip and http in C... and it was not that nice... :S
You can (should) grab a library for that sort of thing. Even so it's going to be more work than some languages. As it happens I have implemented both HTTP client and zip file writer libraries in the past: not in C but in a language at about the same level, so I was sitting on top of zlib and a Berkely-style sockets interface. I don't really recommend it, for a very simple http client it's not all that difficult, just very tedious. Use libcurl and libtar instead (tar since compression isn't actually essential here anyway, so keep it simple)...
The idea is actually awesome. And some internet (well, LAN) connections are faster than disk access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.