Swig with cmake and additional libraries
Question: I am working on a project where I want to use a C++ library in Python. After a
little bit of research I figured out that Swig would be a good way to do it (a
small example worked).

So now I am trying to include Swig into cmake to make things more comfortable.

In my case, I have a really small program to test things:

    
    
    #include "ct.h"
    using namespace std;
    
    int main(int argc, char const *argv[])
    {
        /* code */
        return 0;
    }
    
    int test()
    {
        Image image(10,11);
        cout << "hallo"<< endl;
    
        return 3;
    }
    

The Image class is defined in a header "image.h", which is included in "ct.h".
This is probably the problem here, since the library, which includes the Image
class needs to be linked against the library, which is generated by Swig. I am
not sure about this...And, especially, I don't know how to do this. I was not
able to find anything in the manual.

Anyway, if I want to include the lib in python I get the following error:

    
    
    >>> import kissCT
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "kissCT.py", line 25, in <module>
        _kissCT = swig_import_helper()
      File "kissCT.py", line 21, in swig_import_helper
        _mod = imp.load_module('_kissCT', fp, pathname, description)
    ImportError: ./_kissCT.so: undefined symbol: _ZN5ImageC1Eii
    

The related Swig file looks like this:

    
    
    /* kissCT test module */
    
    %module kissCT
    %{
    #import "ct.h"
    extern int test();
    %}
    extern int test();
    

I hope, all this is not to confusing and I would really appreciate if someone
has an idea what I did wrong.

Edit: the related cmake file looks like [this](http://pastebin.com/m7TTZ1Dv)


Answer: Python needs to be able to find the image library at run time. The simplest
way is to set LD_LIBRARY_PATH environment variable to the folder containing
the image .so file which contains the undefined symbol.

If you run the command "ldd _kissCT.so" it should show you the libraries it
depends on.

