Main Page | Recent changes | Edit this page | Page history

Printable version | Disclaimers | Privacy policy

Not logged in
Log in | Help
 

Magick-Magick++

From KDevelop

Using Magick++ in KDevelop3 by SadaraX

Contents

[edit] What is this?

This is a simple guide to using ImageMagick's Magick++ in KDevelop version 3.2.0 under linux (though it works for most earlier the 3.x.x versions too). Specifically, this is about linking against the libraries inside your KDevelop3 project. So, in theory, this could work for any type of libraries you are trying to include. In fact, I am fairly certain its a good example to help people link their libraries in KDevelop. Regardless this example specifically uses the Magick++ libraries. For more information about what ImageMagick or Magick++ is, check out this website: http://www.imagemagick.org/ .

I experienced major pains in learning how to use Magick++ in KDevelop3, so I am writing this for other people to want to use it and to spare themselves the trouble. I will maintain this tutorial until such time as the development team sees fit to make a better arrangement in their GUI for linking against libraries in KDevelop3 projects.

I am going to assume you know what Magick++ is, and that you want to use it. I don't much care what IDE or whatever you are going to write your code in, since these instructions may very well help anyone. However, I am writing this for people who are using KDevelop3 (not KDevelop2), because I like to use KDevelop3, and it gave me a lot of trouble until I finally got it to work.

I am also going to assume you know generally what a programming IDE (like KDevelop3 or KDevelop2) is and does. I am not going to explain to you about the basics of programming or using an IDE to program in, if you want to learn that, take a class or look around online. There are much better tutorials than this for that.

Lastly, I am using [debian/ubuntu] Linux (my distro is currently from http://www.kubuntu.org) and this is for people who want to program in linux. If you can get KDE working on whatever distro of linux you are running, this tutorial should work for you. ImageMagick should work for windows too, but I don't care enough to check if my tutorial can help you. This is for linux users in KDevelop3.

[edit] Getting Started

  1. Start up KDevelop3. From the pull down menus on the top of the screen, click the "Project" menu. Click "New Project". Create a C++ project by selecting C++, then select "Simple Hello world program". Enter an appropriate directory path and project name, and any other information that you like. [Note: I do not know if this will work for other languages other than C/C++, but since linking libraries is not a language specific thing, it probably will with any of them]
    Image:ImageMagick++_createproject.gif
  2. Hit the next button.

    You can enter whatever information you want at this page. Its rather self-explanatory. You do not have to use a version control system like CVS or Subversion. If you want to use it you can. It really does not matter for the purposes of our demonstration here. Hit none if you do not want to or do not know how to use CVS.

  3. Hit the next button again. This is just a template that KDevelop will create for you each time that you start a new .h file for this project. Leave it blank or add whatever you want to it. I normal leave mine blank. I write my own comment info if I want any.
  4. Hit the next button again. The window should look almost the same. Its doing the template info again, only for your .cpp files. Do whatever you want here.
  5. Hit Finish.

    KDevelop3's the message window at the bottom of the screen may pop up, flash you a bunch of information that you really don't need to know or care about. It may not show up (depending on your version). Either way, that little bit of pop up info is not important. The important thing is that after a little bit, KDevelop should settle down and be like the next step.

  6. Your window should now look something like this, displaying code on your screen:


    Image:ImageMagick++_projectcreated.gif

    #ifdef HAVE_CONFIG_H
    #include "config.h"
    #endif
    #include < iostream >
    #include < cstdlib >
    using namespace std;
    int main(int argc, char *argv[])
    {
      cout << "Hello, world!" << endl;
      return EXIT_SUCCESS;
    }
    
  7. Next, you want to select from the pull down menus "Build" then "Build Active Target".

    KDevelop3 may ask you if you want to "run automake & friends and configure first?", answer yes. Give the program some time, building your project for the first time takes a while, especially if you are running a lot of other programs or you have an older system.

  8. Depending on your version of KDevelop and your configurations, KDevelop may look like its just sitting there, but it is not. If you want to see what its doing, on the bottom of the KDevelop work space, click the "Messages" tab, if that has not already popped up. Right click in the gray area and select either "Short Compiler Output" or "Full Compiler Output" to see what KDevelop and your computer are doing. This may also be a good thing to do if you have an error.
  9. After a minute or so, you will see some other commands display. Wait until you see you the display "linking *program-name* (g++)". After that it will either be finished or print the message "*** Success ***", and it should be done.
  10. If you have a problem compiling at this point, check to make sure you have the program "libtool" installed. This does not always come installed with every version of linux and its a fundamental part for KDevelop3 to work. I often wonder why its not a required dependency to install KDevelop itself. You can install libtool by various means. For example, since I run a debian based system, I simply go the console and from root run "apt-get install libtool", RedHat should have something similar like "apt-rpm install libtool" and Gentoo would use its emerge system. I don't know, but just get that program/package installed on your system whatever way you like.
  11. If you program complains about the #include " " using quotations, just replace them with the < and > characters.
  12. To make sure everything is working properly, select from the pull down menus "Build" then

    "Execute Program". A window should pop up with the words, "Hello, world!", then tell you to hit enter to continue.

  13. If all that worked successfully, then we are doing good. Next, we need to get a hold of the

    Magick++ source files and code so that we can use them in your project. You can download the .tar ball from various sources, like here: Magick++. I am not entire sure if you have to always install the image magick library development package or not to get this program to run. It sometimes seems like I do not need it and other times like I do need it. It seems to me like you should not need to install the development library packages to make use of it in your code if you have the source files for it with your own source code. But what do I know? Anyway, you will still need their source code (the .h and .cpp files from the .tar ball) for our example regardless. So go download it.

  14. Once you have the .tar (or .tar.gz) file, you need to extract the Magick++ folder. After

    you have that extracted, you will need the "lib" folder. Copy that into your source directory in your KDevelop3 project. It should be on a directory path like this: /home/user/C++/temp/src

  15. Place the lib folder in there. Once you have, go look in the lib directory and check to make

    sure that the file "Magick++.h" is there.

  16. If it is there, next add this line of code under your #include statements:

    #include "lib/Magick++.h"

  17. You must use " " on this include statement, since the " " signals to your compiler to look locally at your source code folder for that particular inclusion of code.
  18. Next, select from the pull down menus "Build" then "Build Active Target". It should compile

    and link properly. Wait until you see you the display "linking *program-name* (g++)", wait a second after that, and it should be done.

  19. Alright, if it did not give you any errors, that means that KDevelop3 sees the files you

    placed there and is almost ready to use them. This is a huge step right here, and very important to have done. This can (to my perception) be generally done with most code without having to link libraries. Including the code is easy, but without the proper library linking/inclusion, any calls you make to the code in that extra source code will go badly and fail on compile. But that's what this tutorial is here to FIX!

Next, you need to add the libraries for the program to link against or include.

[edit] Linking Libraries

This method for linking libraries is known to work with KDevelop versions as early as 3.0.1, but has not been tested on earlier versions of program. I have tried just using the graphic input method for the libraries but I have not been able to get it to work. This method manually adds the libraries by inputting the text into the Automake configuration via direct text input.

  1. To add the libraries for the program, you need to find the AutoMake Manager.
    Unfortunately, the programmers who made KDevelop3 (talented people as they are) made a huge user interface mistake here. They put the automake manager in a small little button, in a corner of the application, and made no pull-down menu entries to it. According to the mods of the KDevelop forums, the question about where to add or link libraries against in KDevelop3, "Has been answered a 1000 times" because they put it in such a poor location. You should look for a button on the right-hand side of your screen. My button is under my documentation button and my code snipet button. You can find it be holding your mouse over each button until the title "AutoMake Manager" pops up, if you cannot find the button with the proper label. Once you have found it, left click on it. Or you can right-click on the project itself and select "Options" to take you to the same place.
  2. A file tree window display should pop out from the right hand side of your screen. In the bottom window, select your program. After you have it highlighted, click the little wretch button.
  3. A new window will pop up. At the top of it, click on the "Libraries" tab. From there, click the "Add" button. A little input box will pop up. It will have a "-l" already written in it. In the box, you need to write: -lMagick++


    That is a '-' (dash) + 'l' (L as in Lion) + 'Magick++', all together

  4. Hit OK. Hit OK, again. The window should disappear.
  5. You're DONE!

    You should be able to write most any bit of Magick++ code and it get it to work. You may want to declare 'using namespace Magick;' under your #includes to make your job of coding easier. Just to make sure that you've got everything working properly, lets do some test code anyway.

    #include < iostream >
    #include < cstdlib >
    #include "lib/Magick++.h" // make sure to use the " "
    using namespace std;
    using namespace Magick;
    int main(int argc, char *argv[])
    {
      cout << "Hello, world!" << endl;
      Image img("pic.gif");
      img.write("pic.jpg:);
      return EXIT_SUCCESS;
    }
    
  6. NOTE: Just to mention again, if you do not use the #include "lib/Magic++.h" with the "", you will get an error. The "" signal the compiler to look at the local source file directories for the ImageMagick files, instead of looking in the system's include directory. If you do not do this, you must install the ImageMagick Magick++ development package onto your system (which will place files into your system's include directory for the compiler to use, though this may not always work).
  7. Next, select from the pull down menus "Build" then "Build Active Target". It should compile and link properly. Wait until you see you the display "linking *program-name* (g++)", wait a second after that, and it should be done. If it worked, they everything is perfect and you can code with Magick++ to your heart's content.


[edit] Problems with Image Magick/Magick++ libraries

If you have problems using the ImageMagick libraries with only the steps I mentioned above, you should try installing the development package. Namely, for Magick++, you would want to install libmagick++6-dev. Depending on your linux distro, there are various ways to do this. For me, running Debian linux, installing that is as easy as typing (on the root-console):

apt-get install libmagick++6-dev

If that does not fix it, you have another problem and should consult the forums about it. This pretty much does the trick for me. Like I said, I have tried using the graphical input, but sadly it does not work quite right. Just go ahead with this if all else fails. Good luck everyone!

Retrieved from "http://www.kdevelop.org/mediawiki/index.php/Magick-Magick%2B%2B"

This page has been accessed 1,224 times. This page was last modified 17:49, 3 January 2010. Content is available under GNU Free Documentation License 1.2.


[Main Page]
Main Page
Community portal
Current events
Recent changes
Help
Donations

Edit this page
Discuss this page
Page history
What links here
Related changes

Special pages
Bug reports