18

My compilation fails on ubuntu 12.10 with 300mb memory available (750mb total, 350mb to MySQL), 1.5ghz, I am trying to rework wt's basic hello world file into a simple ajax page. I'm pretty sure it's not a memory issue at heart since I was able to compile the original hello.C file with g++ -O3 -o hello hello.C -lwtfcgi -lwt -lboost_signals.

I'm sure I'm screwing up the c++ since I ripped out the guts of HelloApplication::HelloApplication(const WEnvironment& env) : WApplication(env) and put in the example from the Wt::Json example

HelloApplication::HelloApplication(const WEnvironment& env)
  : WApplication(env)
{
    Json::Object result;
    Json::parse("{ "
             "  \"a\": \"That's great\", "
             "  \"b\": true "
             "}",
             result);

    std::cerr << "Size: " << result.size(); << std::endl; // Size: 2
    WString s = result.get("a");
    bool b = result.get("b");
    std::cerr << "a: " << s << ", b: " << b << std::endl; // a: That's great, b: true
}

I'm new to c++, so I have almost no idea what I'm doing. All I can do is execute the simplest of c++ files.

Here's the original source to the hello world file.

Here's where I got the json sample from.

** Repercussions**

Wow, my respect level just went through the roof for the power of c++.

This has totally destroyed my VPS. I can't restart. I can't even reinstall my distro.

When I finally go into production, I think I'm going to set up a totally different dev system to prevent something like this killing my production system.

  • Don't know why someone downvoted you, seems like a good question. Good luck with this ... +1. – Fantastic Mr Fox Mar 04 '13 at 02:24
  • 4
    First thing I'd try is run the program under valgrind to see if it finds any memory leaks. – Voo Mar 04 '13 at 02:29
  • @Voo Thank-you for the new tool! (new to me) –  Mar 04 '13 at 02:29
  • 2
    Also if compile your program with `g++ -g`, you would have debug symbols built into the binary. You can then run `gdb` on the binary to perform some debugging as well. Quick gdb commands that would be helpful here are `r` to run the program, `bt` to backtrace after any crash or error you encounter. This should point you to the exact point of failure. – Tuxdude Mar 04 '13 at 02:32
  • @Tuxdude Thank-you! I'm racking up on tools tonight! –  Mar 04 '13 at 02:35

4 Answers4

13

As a potential quick fix: You can reduce the memory usage by doing

make -j 1

which tells the build tool to use only one CPU. Worked for me.

Rainer Glüge
  • 1,851
  • 1
  • 15
  • 15
4

Just add a swap file to solve this problem!

// Create a swap file 1 GB

  1. dd if=/dev/zero of=/swapfile1 bs=1024 count=1048576
  2. chown root:root /swapfile1
  3. chmod 0600 /swapfile1
  4. mkswap /swapfile1
  5. swapon /swapfile1

// Edit fstab file

  1. vi /etc/fstab

//Append the following line at the end of file

  1. /swapfile1 none swap sw 0 0

// Check the swap is ready or not

  1. free -m
OKNOIR
  • 41
  • 2
2

Since your compilation fails with out of memory, there's probably not enough memory to compile your program. This can't possibly be because of 'a session management problem' as suggested in the accepted answer. Is mysql eating more than it should? Is 300MB enough to compile C++ anyway?

Serving JSon (like for a REST interface) in Wt is done through a WResource bound to the WServer object. WApplication is for an interactive user interface.

user52875
  • 3,020
  • 22
  • 21
  • If that small segment of code can't be compiled with 300mb, that's one heavy set of code! I can run a far more complex websocket++ or java-websocket server for a few 10s of mb. All that above did was simply receive some json and output parts of it to terminal. –  Jan 01 '14 at 10:01
1

Try make -j also this working for my real time application