Author Topic: Numpty Linux Question  (Read 6530 times)

Offline BigAngryDog

  • Multiple posting newcomer
  • *
  • Posts: 75
    • BigAngryDog.com
Numpty Linux Question
« on: June 06, 2006, 10:56:31 pm »
Really numpty question. I'm emarrassed about my ignorance, but here goes...

If I were to build an executable binary under Linux, then in principle, could I upload the binary to any Apachie server for use and execution within a website? I.e. could I use the binary to generate HTML content? Or do I need to start worrying about which distribution of Linux my binary is built for?

Thanks :)
BigAngryDog.com

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Numpty Linux Question
« Reply #1 on: June 07, 2006, 12:05:26 am »
Or do I need to start worrying about which distribution of Linux my binary is built for?
Yes. In the end, it's still an executable and it's still run by the OS.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Numpty Linux Question
« Reply #2 on: June 07, 2006, 12:10:54 am »
No, and yes.

In principle, you can do that, but it is not quite that easy. Google for "cgi" or "common gateway interface", or read this primer to get an idea how this works.

Also, you must make sure that you enable cgi in your web server (which may be a security issue, you may want to think twice about that).
Cgi is not necessarily enabled by default on a web server (or available at all), and if it is enabled, it usually only works in one specific subdirectory (so it also matters where you upload your program to).

Lastly, it does matter what kind of Linux you use insofar as you may use an incompatible version of glibc or any other library that you link to. So yes, you have to take care of that.

EDIT:
For completeness: Besides CGI, there is also FastCGI (which is supposedly faster ;)) and the possibility to incorporate executable code into a web server via some plugin mechanism (most major servers support that). Both FastCGI and plugins have the advantage that they do not need to reload the executable for every request.
I cannot tell you much more about FastCGI since I have never used it, but I guess it does not matter a lot unless you plan to run your program 100 times per second. Writing a module/plugin is evidently a lot more complicated than a simple CGI, so that is probably not what you want, either.

Unless whatever you want to do is about some insane number crunching or similar things, you might consider a script language, too. For example PHP is available nearly everywhere (even the cheap web hosters offer it), and it is a mighty fine thing. You have a syntax very close to C/C++ (learning time is almost zero), there is a function for almost everything (including database handling, networking, graphics and all kinds of weird stuff), the documentation is excellent, and execution speed is not a lot worse than a real executable. Using PHP, you can reduce the amount of time to write a "typical" web application to maybe 10% of what you would take doing it in C/C++.
« Last Edit: June 07, 2006, 12:19:49 am by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Balazs

  • Guest
Re: Numpty Linux Question
« Reply #3 on: June 07, 2006, 01:57:29 am »
I personally prefer Perl with CGI.pm and the plethora of related modules from CPAN :)

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Numpty Linux Question
« Reply #4 on: June 07, 2006, 03:03:05 am »
As always, it depends on what you want, what you have available, and what you're used to. :)

If you are adept to Perl, then it is surely a mighty fine language, in particular when it comes to whacking character strings with regular expressions and similar things. There is probably no other language that lets you do more fancy string manipulations in a single line of code.
However, Perl's syntax is outright repelling if you are not used to it, and it can be a pain to learn (and understand). That may be the main reason why Perl projects have the reputation of becoming unmanageable at some point ;)

Neither Perl nor PHP have the cutting edge speed of a "real" executable, but they can make your life a lot easier if you use the right tool for the right job (and if you can handle the tool).

PHP has (almost) all the good features of Perl, but keeps the advantage of being 100% noob-safe and 80-90% downwards-compatible to C/C++. This can really be a huge advantage  (you don't need to learn much more than to put a $ in front of variables, and to concatenate strings with . rather than +. Well, maybe you should know what an associative array is too, but that's about it ;)).
That way, you can almost copy and paste your existing C code, insert a few dollar signs, and that's it. With the only difference that you can now implement session handling and authentication via a SQL database in like 5 lines of code, and a basic shopping cart in like 10 more lines of code, and it will just work like magic. And if you need <insert arbitrary function> then chances are good that you don't need to worry about implementing it, as most everything you'll ever need is in the standard library. :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Balazs

  • Guest
Re: Numpty Linux Question
« Reply #5 on: June 07, 2006, 02:49:26 pm »
Just code a little in Perl, and you'll never want to get back to C++ ever again. I know, I hate C++ since the day I started learning Perl :)

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Numpty Linux Question
« Reply #6 on: June 07, 2006, 06:14:41 pm »
Just code a little in Perl, and you'll never want to get back to C++ ever again. I know, I hate C++ since the day I started learning Perl :)

Kind of the same way I thought about C++ when I was learning python, but Perl and Python have there limitations.  Generally Perl/Python and C++ are in different application domains.

P.S. From a Pythoner- Perl just looks ugly ;), but I have never written anything in it and that is  a very objective opinion of course.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Numpty Linux Question
« Reply #7 on: June 07, 2006, 06:27:41 pm »

sethjackson

  • Guest
Re: Numpty Linux Question
« Reply #8 on: June 07, 2006, 07:37:44 pm »

Balazs

  • Guest
Re: Numpty Linux Question
« Reply #9 on: June 08, 2006, 12:59:47 am »
Oh well, Perl is indeed a bit cryptic, but not more than C++ with all it's template glory :)

And about Python: I never used it, but someone already told me, that I should try it. He said, that if I like Perl, I will like Python more for sure. Dunno, maybe I'll try it one day...

BTW: did you know, that Perl is an object-oriented language? This is no joke, really, but I was just as shocked when I first read it can do OO :)
« Last Edit: June 08, 2006, 01:02:30 am by Balazs »

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Numpty Linux Question
« Reply #10 on: June 08, 2006, 04:04:16 am »
Many programming languages can do OO nowdays, even the scripted ones like Perl, Tcl/tk and Python. I've never tried Perl, Tcl/tk syntax is awful and Python is just lovely, but what I love the most of C/C++ is the performance and how close they're to the machine.

Now, getting a bit more on-topic, PHP, Perl, Tcl and Python do really look like a better choice than CGI nowdays for that purpose.

If you want to do it the CGI way, you'll really have to worry. "Thinking In C++" (it's a book you can get for free) could help you a bit since one of its chapters is about CGI (I've never read it myself, so I don't know how much it really covers).

Offline BigAngryDog

  • Multiple posting newcomer
  • *
  • Posts: 75
    • BigAngryDog.com
Re: Numpty Linux Question
« Reply #11 on: June 08, 2006, 06:16:55 am »
Hey! Thanks for the replies.

>it does matter what kind of Linux you use insofar as you may use an incompatible version of glibc or any other library that you link to

This raises a more general question for me. If I produce a Linux app, say I build it under SuSe Linux, is the binary going to run on Redhat or Urbuntu? How do I ensure compatibility? Is it easy to produce an out-of-da-box application which can simply be installed and executed?

Having spent most of my time programming for Windows, I'm new to this area. However, the combination of CodeBlocks and wxWidgets has opened up a new and exciting area for me.

Thanks for the suggestions on using scripts. At this stage I'm only exploring possibilities. Rather than being stuck with producing client-only applications, it would be great if I could run them from a server. I don't know whether I will use a binary or a scripting language. Have hacked about with Perl & Tk in the past. However, Python looks more promising.

Thanks again. :)
BigAngryDog.com