0

I apologize if this seems like a stupid question, but I guess I am more used to packages that come with Makefiles or configure scripts.

I downloaded the Mongoose source tar file from the site, and untarred it.

I then tried to compile an executable out of it using gcc -g -c mongoose.c -o main.o -lpthread -ldl. However, after trying to execute, I get the error -bash: ./main.o: cannot execute binary file

When I looked into mongoose.c source, I did not find a main function.

Where can I get the main function so that the Linux mongoose web server can be compiled to work the same way as the Windows mongoose.exe?

merlin2011
  • 71,677
  • 44
  • 195
  • 329

2 Answers2

3

Mongoose does come with a Makefile, and will compile as a standalone command-line program. Lua and SQLite are included.

The easiest way to compile the latest version is to cd into the "build" directory and run make unix. I'm not sure about the archived version on the downloads page, but trunk has been pretty stable.

I just checked out a clean copy of Mongoose from github earlier tonight and built it with no problems, so I can confirm that this works (assuming you have any other dependencies set up properly, of course).

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • 1
    Mongoose no longer has a ./build directory, and the developer isn't very helpful, possibly because Mongoose is now partly a commercial product. – Gulbahar May 05 '14 at 14:05
  • 2
    @Gulbahar you probably already know this but the [Civetweb](https://github.com/bel2125/civetweb) fork retains the MIT license, is actively developed, and has detailed [build instructions](https://github.com/bel2125/civetweb/blob/master/docs/Building.md). – Dagg Nabbit May 06 '14 at 17:55
1

It's because mongoose is not supposed to be used standalone, but to "embed" it into your program. You need to create a program which calls the correct function from mongoose.c.

Also, the -c flag to GCC tells it to create an object file, which needs to be linked to create an executable. So you try to execute a file which is not executable.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 1
    Why does the windows version of mongoose come with a standalone program while the *nix version does not? I expected a *nix version to include a standalone build for that reason. – merlin2011 Oct 17 '13 at 07:09
  • 1
    @merlin2011 source code archive have no main function so it cannot be fully the same thing used in provided windows executable (which contains a lot other things like SSL, lua, etc. - none of them are part of core mongoose source code). The only one who could answer your question is developer/maintainer of their windows bundle, please ask them if you like to - although i wouldn't be surprised if you'll be the first one who wanted this functionality, it's certainly not mongoose intended use case. – keltar Oct 17 '13 at 08:09