{"id":2279,"date":"2016-11-10T11:22:10","date_gmt":"2016-11-10T19:22:10","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=2279"},"modified":"2017-01-05T10:47:13","modified_gmt":"2017-01-05T18:47:13","slug":"simplifying-library-development-with-exported-settings","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/libraries\/msbuild\/","title":{"rendered":"Simplifying Library Development with Exported Settings"},"content":{"rendered":"<p>This tutorial shows how to use the new Exported Settings feature of VisualGDB MSBuild projects to simplify the use of library projects. We will show how to avoid manually adding include directories and extra libraries to all projects referencing your library project to save time and avoid mistakes.<\/p>\n<p>Before you begin, install VisualGDB 5.2 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Linux Project Wizard. The steps below will also work for Embedded projects as long as you are using MSBuild:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2280\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/01-newprj.png\" alt=\"01-newprj\" width=\"786\" height=\"565\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/01-newprj.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/01-newprj-300x216.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><br \/>\n<\/a><\/li>\n<li>First we will create a normal application project that will use our library, so select &#8220;New project -&gt; Application -&gt; MSBuild&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/02-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2281\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/02-msbuild.png\" alt=\"02-msbuild\" width=\"745\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/02-msbuild.png 745w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/02-msbuild-300x267.png 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/a><\/li>\n<li>On the next page select your target computer. The steps described below will work for both remotely built projects and projects built with cross-toolchains:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/03-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2282\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/03-target.png\" alt=\"03-target\" width=\"745\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/03-target.png 745w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/03-target-300x267.png 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/a><\/li>\n<li>If you are building the project remotely, specify where to store the source files on the remote machine:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/04-sources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2283\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/04-sources.png\" alt=\"04-sources\" width=\"745\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/04-sources.png 745w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/04-sources-300x267.png 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the project. Now we will add the library project. Right-click in Solution Explorer and select Add-&gt;New Project:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/05-prj2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2284\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/05-prj2.png\" alt=\"05-prj2\" width=\"977\" height=\"640\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/05-prj2.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/05-prj2-300x197.png 300w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/li>\n<li>Select &#8220;New Project -&gt; Static Library&#8221; and repeat the rest of the wizard steps you did when creating the main project:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/06-lib.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2285\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/06-lib.png\" alt=\"06-lib\" width=\"822\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/06-lib.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/06-lib-300x242.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Add a reference from the main application project to the library project:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/07-addref.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2286\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/07-addref.png\" alt=\"07-addref\" width=\"746\" height=\"374\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/07-addref.png 746w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/07-addref-300x150.png 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/a><\/li>\n<li>The library project defines a demo function called DemoLibraryTest() in DemoLibrary.h. Try including DemoLibrary.h from your main project to use this function:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/08-demolib.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2287\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/08-demolib.png\" alt=\"08-demolib\" width=\"977\" height=\"640\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/08-demolib.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/08-demolib-300x197.png 300w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a>Despite referencing the project, this will result in an error, as project references normally only affect linking, but not compilation.<\/li>\n<li>On regular Visual Studio projects, the solution would be to manually add the directory of the library project to the application project&#8217;s include directories. You would need to repeat that for each project referencing your library. VisualGDB offers a simpler solution: open the Visual Studio project properties for the <strong>library project<\/strong> and go to the Exported Settings page. Then add &#8220;.&#8221; to the Include Directories field:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/09-inc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2288\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/09-inc.png\" alt=\"09-inc\" width=\"822\" height=\"558\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/09-inc.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/09-inc-300x204.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>If you build the project now, it will succeed:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/10-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2289\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/10-build.png\" alt=\"10-build\" width=\"977\" height=\"667\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/10-build.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/10-build-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/10-build-130x90.png 130w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a>Note that we did not need to change anything in the application project except for adding a reference. If you have several projects referencing your library and want to change the include directories it exports, you only need to do this once for the library project itself.<\/li>\n<li>Modify DemoLibraryTest() to call the pthread_create() function:\n<pre class=\"\">#include &lt;pthread.h&gt;\r\n\r\nvoid *ThreadBody(void *)\r\n{\r\n\u00a0\u00a0\u00a0 return NULL;\r\n}\r\n\r\nint DemoLibraryTest()\r\n{\r\n\u00a0\u00a0\u00a0 pthread_t thread;\r\n\u00a0\u00a0\u00a0 pthread_create(&amp;thread, NULL, ThreadBody, NULL);\r\n\u00a0\u00a0 \u00a0return ++s_Test;\r\n}<\/pre>\n<p>Note how this results in a link error because of a missing reference to libpthread:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/11-undefined.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2290\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/11-undefined.png\" alt=\"11-undefined\" width=\"977\" height=\"667\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/11-undefined.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/11-undefined-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/11-undefined-130x90.png 130w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/li>\n<li>A normal solution would be to add &#8220;pthread&#8221; to library list of each application that uses your library. With the new exported settings feature you can add it just once on the Exported Settings page and all referencing projects will automatically pick it up:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/12-pthread.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2291\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/12-pthread.png\" alt=\"12-pthread\" width=\"822\" height=\"558\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/12-pthread.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/12-pthread-300x204.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>The build will now succeed without having to modify the application again:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/13-buildok.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2292\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/13-buildok.png\" alt=\"13-buildok\" width=\"977\" height=\"667\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/13-buildok.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/13-buildok-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/13-buildok-130x90.png 130w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/li>\n<li>You can also use this mechanism to export preprocessor macros. E.g. you can add USING_DEMO_LIBRARY macro to each of the projects referencing your library:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/14-using.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2293\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/14-using.png\" alt=\"14-using\" width=\"822\" height=\"558\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/14-using.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/14-using-300x204.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>You can use the macro to make the library-dependent code conditional:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/15-ifdef.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2294\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/15-ifdef.png\" alt=\"15-ifdef\" width=\"977\" height=\"667\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/15-ifdef.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/15-ifdef-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/15-ifdef-130x90.png 130w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/li>\n<li>Removing the reference to the library will automatically remove the USING_DEMO_LIBRARY macro and stop the main application from using the functionality from the library:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/16-noifdef.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2295\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/16-noifdef.png\" alt=\"16-noifdef\" width=\"977\" height=\"667\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/16-noifdef.png 977w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/16-noifdef-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/11\/16-noifdef-130x90.png 130w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the new Exported Settings feature of VisualGDB MSBuild projects to simplify the use of<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[33,131],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2279"}],"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=2279"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2279\/revisions"}],"predecessor-version":[{"id":2296,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2279\/revisions\/2296"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=2279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=2279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=2279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}