0

I am new to C++ and plugin development. I am working with/for Unix and for the Firefox browser. So here we go: I have a plugin which uses some classes from a own library. The problem is: it kills my browser asap. I cant even start my browser as soon as MyPlugin.so is in the plugin folder of the Firefox. The library is build and doesn't kill a desktop application that uses it. My guess is that I failed at linking my library with CMake or forgot to include some stuff from FireBreath. So here are the two things I assume are wrong, maybe someone can help me out.

1) (wrong?) linking with Cmake: I added some of these at the end of the CMakeLists.txt of my project. The paths are where the library is.

    add_definitions(-L${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/bin)
    add_definitions(-I${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/src)
    add_definitions(-lcoala64) [name of the library]
    add_definitions(-Wl,-rpath=${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/bin)
    add_definitions(-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/harfbuzz  -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0)

And used the prepmake.sh to generate my build files. Then I followed up with adding flags manually (because I dont know a better solution) to the in the /buid/projects/MyPlugin/CMakeFiles/MyPlugin.dir/link.txt

    -L/home/username/swp/dev/lib/bin
    -I/home/username/swp/dev/lib/src
    -lcoala64 -Wl,-rpath=/home/username/swp/dev/lib/bin

Afterwards I could build the plugin. It builds, so one could assume I have linked correctly. But said crashes appear as soon as I want to use it.

2) Do I use the library wrong? I include like this in MyPluginAPI.h:

    #include <string>
    #include <sstream>
    #include <boost/weak_ptr.hpp>
    #include <boost/smart_ptr.hpp>
    #include "JSAPIAuto.h"
    #include "BrowserHost.h"
    #include "X11/X11KryptoKoala.h"
    //Include from my own library:
    #include "../../../lib/src/Key.hpp"

As soon as I add the following line to MyPlugin.cpp I get the mentioned crashes while the same line works without a problem in the desktop application that uses the same library:

    Key key(password_);

Now I hope this isn't a too big wall of text and someone is willing to investigate and answer to me.

dimka
  • 1

1 Answers1

1

You shouldn't use add_definitions() in that way. CMake allows to differentiate your directives in different categories, so that they only go in the necessary command line. You should use:

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
 include_directories(/usr/include/gtk-2.0  
                     /usr/include/cairo
                     etc. etc.
                    )
 add_library(the_name_of_your_target gtk-x11-2.0 gdk-x11-2.0 ETC. ETC.)
 link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/bin)

Furthermore, there are FindPackage functionalities that can help you setting automatically variables containing the name of your libraries, their directories, their include path.

Most information can be found here and here

Then: What is then prepmake.sh? Are you running cmake at all? Can you use cmake-gui, and then select one canonical build system, like make or ninja?

Finally: It could be that you have a crash because your library are not in your library path. I assume you are under linux, here are some ideas: LD_LIBRARY_PATH vs LIBRARY_PATH and LD_LIBRARY_PATH

Community
  • 1
  • 1
Antonio
  • 19,451
  • 13
  • 99
  • 197
  • to clarify, prepmake.sh is just a helper that calls cmake to do an out of source build; we use it to help people not familiar with cmake to not shoot themselves in the foot as quickly – taxilian Jun 24 '13 at 21:37
  • Yeah; I started that before I myself was fully familiar with cmake, and I'd love to change a lot of things, but simply don't have time – taxilian Jun 24 '13 at 22:26
  • Hey, thanks for the ideas. Sadly it didnt help at all. I did what you suggested and checked with ldd if my plugin links my library to the correct path and it did. I guess the PluginContainer of FireFox doesnt like it or something. – dimka Jun 26 '13 at 17:42