TrisT TrisT - 1 month ago 5
C++ Question

Executing code during runtime that cannot be included in the main program

I'm coding a web server for fun and I'm now trying to make it dynamic.
I need to do the part usually PHP would do in regular web development, be inside the page code and be executed server side while the server runs.

Now, I've been thinking, and reading a bit on this. I could separate it and then invoke the compiler to make that code run, but I've also read that's not a good way to go about it, so I'd like to avoid it.
I thought maybe if I compiled a program that would go with the specific page it was meant to and made it change the page based on arguments and return the page in buffers, it could work, but that just seems cumbersome.

One wouldn't want to include the code for every single page on the webserver because it just doesn't scale well.

I don't believe C++ can do a "CALL" as in batch when the program is running, it would though, I believe, be the ideal solution besides including a file mid program which isn't possible.

I would like to know whether or not there's a way of executing a program or non-included code during runtime and if so how.


You could try dlopen, dlsym, dlerror and dlclose. These allow you to, at runtime, load libraries. Your server could use it to load code which should execute inside a page.

Howto, by Aaron Isotton

Documentation on