Fix the “error while loading shared libraries: libboost_thread.so.1.48.0: cannot open shared object file: No such file or directory” error

Yet another c++ error that isn’t immediate to recover: I wanted to compile and run a program that uses the awesome Boost libraries, but after successfully compiling the program against the libraries I managed to download and install I got the error in the title.

After some googling, I found that you have to add the path to the boost libraries to the environment variable LD_LIBRARY_PATH. You can check whether that’s the problem you have by running your program in a shell like this:

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
./my_program

Replace /usr/local/lib/ with the path you chose to install boost libraries to (that’s the default path if you installed them as root).

If your program runs fine, there’s your problem!

To make changes permanent in Ubuntu you have to add a new configuration file for ldconfig:

sudo vim /etc/ld.so.conf.d/libboost.conf

(my editor of choice is VIM, and the name of the file itself doesn’t matter)
Add the library path to that file, i.e. /usr/local/lib/.
Save the file, quit and reload your configuration by calling

sudo ldconfig

Note that your LD_LIBRARY_PATH won’t change, but your program will now run!

Advertisements

Set fullscreen windows to go over gnome-shell’s (and Unity’s) top panel (top bar) with python/C++ and Glade

I know that there’s a function called fullscreen() that you can call on a window to set it fullscreen. I also know that my screen resolution is 1920×1080, so I supposed that explicitly setting the window’s height and width to the exact screen size would have forced mutter to put my window above everything else.

But…

No, it doesn’t. There’s a sneaky little option called Window Type that has to be set to Popup to make gnome’s top bar surrender and let your window dominate the screen. You can find it in the General tab in Glade (it’s the third field in Glade 3.10.0, I don’t know about the other versions).

Is this some kind of common knowledge that doesn’t have to be put on tutorials? I find the lack of documentation on GTK+3 disturbing.. 🙂 (I know that the API is quite well documented, but we’re still missing the plethora of examples you can find for GTK+2 on the web)

Testing a class with a non-zero argument constructor in Google Test

Of all the C++ testing libraries I googled for, the most powerful and easiest to use seems to be… er… Google’s 🙂

Me being mostly a Java/Python programmer (and proud to be!), I still can’t find it “easy” but… it’s mostly like using JUnit (well, mostly).

You get your SetUp() and TearDown() functions, your ::testing::Test class to extend and your TEST_F()s with all their EXPECT_whatever() to be run stuffing ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); into your main() function.

Ok, the first test I wrote actually shattered my “oh-my-it’s-just-like-JUnit!” dream.. I just wanted to write a test for a class that needs a std::string as argument. The easiest way I found to do that is to have your test class extend the class under test, and wrap the super class constructor with a no-args one.

Here’s what I did:

#include "gtest/gtest.h"
#include "my_class.h"

using namespace std;

class MyClassTest: public ::testing::Test, public MyClass {
  public:
    static string test_path_;
    string pathname() {
      return pathname_; // as it's a protected field in MyClass
    }
  protected:
    MyClassTest() :
      MyClass(test_path_) {
    };
    virtual void SetUp() {
      my_class_test_ = this;
    }
    MyClassTest* my_class_test_;
};

string MyClassTest::test_path_ = "test";

// Tests that MyClass constructor sets the correct path
TEST_F(MyClassTest, Constructor) {
  EXPECT_STREQ("test", my_class_test_->pathname().c_str());
}

Of course this is just a toy to understand the framework, but it’s a little example I couldn’t easily find on the web right now..
I’m no C++ expert at all, so if anyone reading this feels insulted by something I wrote, please, please post a comment and teach me how this should be done, I’m more than willing to learn! 🙂

[Update – July 2013]: Mark Abraham posted how it’s done, just scroll down to his comment!