{"id":149,"date":"2014-02-04T17:39:31","date_gmt":"2014-02-04T17:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=149"},"modified":"2015-07-19T09:01:53","modified_gmt":"2015-07-19T16:01:53","slug":"linux-imagemagick","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/ImageMagick\/","title":{"rendered":"Using ImageMagick Library in C++ Linux Projects"},"content":{"rendered":"<p>This tutorial demonstrates the use of external Linux libraries in VisualGDB projects. We will create a Linux project that rotates images using the <a href=\"http:\/\/www.imagemagick.org\/Magick++\/\">M<span class=\"auto-style1\">agick++<\/span><\/a> library.<\/p>\n<ol>\n<li>Open Visual Studio. Select &#8220;File-&gt;New-&gt;Project&#8221;, then select &#8220;VisualGDB-&gt;Linux Project Wizard&#8217;. Specify project name and location and press the OK button:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/01-newproj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/01-newproj.png\" alt=\"01-newproj\" width=\"700\" height=\"484\" \/><\/a><\/li>\n<li>On the first page select &#8220;Application&#8221; and press &#8220;Next&#8221;: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/02-application.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/02-application.png\" alt=\"02-application\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>On the next page select the Linux computer you want to use. We will now need to install the Magick++ library on it, so press the console button to the right from the computer selection to open a new SSH console:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/03-selectmachine.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/03-selectmachine.png\" alt=\"03-selectmachine\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>Install the <strong>libmagick++-dev<\/strong> package. If you are running a Debian-based Linux distro, run the following command in the console window:\n<pre>sudo apt-get install libmagick++-dev<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/04-libinstall.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/04-libinstall.png\" alt=\"04-libinstall\" width=\"684\" height=\"423\" \/><\/a>When the package is installed go back to the VisualGDB wizard and press &#8220;Next&#8221;.<\/li>\n<li>To let the Linux machine easily access files from the Windows project folder we will use a shared folder instead of transferring the files. Select &#8220;Mount a shared Windows folder&#8221; and click &#8220;Setup&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/05-mountfolder.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/05-mountfolder.png\" alt=\"05-mountfolder\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>VisualGDB will suggest sharing one of the folders containing the project folder. In this example the project resides in <strong>c:\\projects\\RotateDemo<\/strong> and we will share <strong>c:\\projects. <\/strong>To let the Linux computer access your shared folder you will need to provide valid credentials:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/06-newshare.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/06-newshare.png\" alt=\"06-newshare\" width=\"500\" height=\"362\" \/><\/a><\/li>\n<li>When you press OK VisualGDB will let you select the mount point where you want to map your folder. In this example we use \/opt\/VisualGDB-projects:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/07-mount.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/07-mount.png\" alt=\"07-mount\" width=\"500\" height=\"216\" \/><\/a><\/li>\n<li>Once the folder is shared and mounted use the diagram at the bottom if the wizard page to recheck the relation between the Windows and Linux paths:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/08-mountsetup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/08-mountsetup.png\" alt=\"08-mountsetup\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; when done. VisualGDB will create a &#8220;Hello, World&#8221; project. Build it by pressing Ctrl-Shift-B:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/09-helloproj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/09-helloproj.png\" alt=\"09-helloproj\" width=\"707\" height=\"626\" \/><\/a><\/li>\n<li>As we have configured shared folders, the Linux computer will be able to automatically access all files from the Windows project directory and write files to it as well. Create a file called <strong>ArrowRight.png<\/strong> in the project directory and draw an arrow in it:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/10-arrow.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/10-arrow.png\" alt=\"10-arrow\" width=\"698\" height=\"458\" \/><\/a><\/li>\n<li>Now we will need to configure IntelliSense to support the ImageMagick headers. Right-click on the project, select VisualGDB Project Properties, go to the IntelliSense page:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/11-includedirs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/11-includedirs.png\" alt=\"11-includedirs\" width=\"700\" height=\"585\" \/><\/a><\/li>\n<li>Click &#8220;Add Remote&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/12-addremote.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/12-addremote.png\" alt=\"12-addremote\" width=\"580\" height=\"104\" \/><\/a><\/li>\n<li>Click the browse button and select \/usr\/include\/ImageMagick:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/13-browse.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/13-browse.png\" alt=\"13-browse\" width=\"368\" height=\"320\" \/><\/a><\/li>\n<li>Press &#8220;OK&#8221; in all the dialogs to save your settings. VisualGDB will add the directory to the IntelliSense search path. If you have installed other libraries recently, click &#8220;Edit Remote Cache&#8221;, select all directories and press &#8220;Reload&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/14-reload.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/14-reload.png\" alt=\"14-reload\" width=\"700\" height=\"241\" \/><\/a><\/li>\n<li>Replace the contents of the main source file with the following:\n<pre>#include&lt;Magick++.h&gt;\r\n#include&lt;stdio.h&gt;\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n    if (argc &lt; 3)\r\n   {\r\n       printf(\"Usage: %s &lt;Input file&gt; &lt;Output file&gt;\", argv[0]);\r\n        return 1;\r\n   }\r\n\r\n   printf(\"Opening...\\n\");\r\n   Magick::Image img(argv[1]);\r\n\r\n   printf(\"Rotating...\\n\");\r\n   img.rotate(45);\r\n\r\n   printf(\"Saving...\\n\");\r\n   img.write(argv[2]);\r\n\r\n    return 0;\r\n}<\/pre>\n<p>If you try to build your project now you will get an error message:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/15-noinclude.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/15-noinclude.png\" alt=\"15-noinclude\" width=\"707\" height=\"626\" \/><\/a><\/li>\n<li>The error is shown because GCC include directories are managed separately from IntelliSense include directories. To fix the GCC includes open the <strong>flags.mak<\/strong> file and add <strong>\/usr\/include\/ImageMagick <\/strong>to the <strong>INCLUDE_DIRS<\/strong> statement. If you build your project now the compilation will succeed but you will get several linker errors instead:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/16-linkerror.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/16-linkerror.png\" alt=\"16-linkerror\" width=\"707\" height=\"626\" \/><\/a><\/li>\n<li>To fix the linker errors you will need to add the <strong>Magick++<\/strong> library to the <strong> LIBRARY_NAMES<\/strong>:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/17-linkdone.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/17-linkdone.png\" alt=\"17-linkdone\" width=\"707\" height=\"626\" \/><\/a>Note that the actual library file is called <strong>libMagick++.a<\/strong> and is located in one of the standard library directories. We omit the <strong>lib<\/strong> prefix in the flags.mak file as GCC traditionally requires it.<\/li>\n<li>Now we need to provide the command-line arguments to our program and run it. The easiest way to do it is to use the VisualGDB toolbar. Enable the toolbar by right-clicking in the toolbar area and selecting VisualGDB. Then enter &#8220;ArrowRight.png ArrowRotated.png&#8221; in the text field:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/18-args.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-18\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/18-args.png\" alt=\"18-args\" width=\"707\" height=\"626\" \/><\/a><\/li>\n<li>Press F5 to run the program to the end or F10 to step into it:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/19-completed.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-19\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/19-completed.png\" alt=\"19-completed\" width=\"707\" height=\"626\" \/><\/a><\/li>\n<li>Open the project folder in Explorer and check out the ArrowRotated.png file created by the program:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/20-rotated.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/20-rotated.png\" alt=\"20-rotated\" width=\"698\" height=\"458\" \/><\/a><\/li>\n<li>You can always see the program output from the last debugging session using the VisualGDB Program Output view in the Output pane in Visual Studio:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/21-log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-21\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/ImageMagick\/21-log.png\" alt=\"21-log\" width=\"707\" height=\"626\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial demonstrates the use of external Linux libraries in VisualGDB projects. We will create a Linux project that rotates<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[79,33],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/149"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/149\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}