{"id":266,"date":"2010-01-14T13:24:27","date_gmt":"2010-01-14T19:24:27","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=266"},"modified":"2011-04-27T19:34:46","modified_gmt":"2011-04-28T01:34:46","slug":"visualc-2008-for-gcc-sdl-people","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2010\/01\/14\/visualc-2008-for-gcc-sdl-people\/","title":{"rendered":"VisualC++ 2008 for gcc \/ SDL people"},"content":{"rendered":"<p>I&#8217;ve had to port a project to VC 2008 from my usual mingw setup. \u00a0Here&#8217;s what I did. \u00a0This covers quite a few things, in particular where to find common GCC settings in VC land.<\/p>\n<div><strong>Setting up the project<\/strong><\/div>\n<ol>\n<li>New project<\/li>\n<li>Type: win32<\/li>\n<li>Template: Win32 console if you want a console. \u00a0Or just Win32 Project if you don&#8217;t want the console to pop up.<\/li>\n<li>Choose a name for your project<\/li>\n<li>The solution name is the folder everything gets put in. \u00a0In VC, you can have several projects within a single solution.<\/li>\n<li>On App settings, I choose Windows application, Empty project<\/li>\n<\/ol>\n<p><strong>Adding the source files<\/strong><\/p>\n<ol>\n<li>I right click on my project name and Add&gt;New filter, and use that to bundle a few different sets of source files together<\/li>\n<li>This is done so that VC will compile the files, but keep in mind that the separations don&#8217;t seem to mean anything to VC. \u00a0It&#8217;s just for your visual convenience.<\/li>\n<li>Note that if there are two files with the same base name &#8220;dostuff.c&#8221; and &#8220;dostuff.cc&#8221; this will cause VC to choke during compilation as it will create two .obj files with the same name and fail during linking.<\/li>\n<li>VC doesn&#8217;t support C99 so any C99 files will have to be Right Click &gt; Properties &gt; C\/C++ &gt; Advanced &gt; Compile as &gt; C++ Code<\/li>\n<\/ol>\n<p>Note: a Project can have a number Configurations (Debug, Release ..) If you are targeting a certain distribution site with some special requirements you can add more Configurations via Solution &gt; Properties &gt; Configuration Manager &gt;<\/p>\n<p><strong>Compilation Options<\/strong><\/p>\n<p>Adding some project compile time options (mainly -D and -I equivalents for specific defines and include folders.) \u00a0Keep in mind which Configuration you are modifying at all times. \u00a0You can also switch to &#8220;All Configurations&#8221; for global changes.<\/p>\n<ol>\n<li>(GCC -I) \u00a0To add in include folders, Project &gt; Configuration Properties &gt; C\/C++ &gt; General &gt; Additional Include Directories &gt; &#8230; I found with include folders you often need to stack on a few ..\/..\/&#8217;s to get it to point at what you want it to point at. \u00a0(In my project I&#8217;ve got my VC project separate from all my source code, so everything is up and over a few folders.)<\/li>\n<li>(GCC -D) \u00a0To add in defines, Project &gt; Configuration Properties &gt; C\/C++ &gt; Preprocessor &gt; Preprocessor Definitions &gt; .. I often add a few of these to tell the code what build we&#8217;re doing. \u00a0(iPhone vs, Windows, vs Linux, etc)<\/li>\n<li>(GCC -W) \u00a0Although warnings might be useful .. They made it impossible to see the errors. \u00a0You can turn down the warnings from level 3 to 1 in Project &gt; Configuration Properties &gt; C\/C++ &gt; General &gt; Warning Level &gt;<\/li>\n<li>(GCC -l) \u00a0Linked libraries are probably going to be needed. \u00a0Again in my project I&#8217;ve often got a few ..\/..\/&#8217;s in the paths. \u00a0Here&#8217;s where you add this stuff: Project &gt; Configuration Properties &gt; Linker &gt; Input &gt; Additional Dependencies &gt;<\/li>\n<li>.. an alternate way is to add #pragma comment(lib,&#8221;MyLib.lib&#8221;) into your main.cpp. \u00a0By doing this you can refer to a lib right within your source if you prefer.<\/li>\n<li>For whatever reason, you may need to exclude some libs from being compiled into your project. \u00a0(If you see errors like &#8220;_tolower already defined in MSVCRTD.lib, etc). \u00a0You can exclude a lib in Project &gt; Configuration Properties &gt; Linker &gt; Input &gt; Ignore Specific Library &gt; .. (in my case, I had to add msvcrt.lib and libcmt.lib)<\/li>\n<li>For my project I needed to expand the size of my stack, due to having excessive amounts of static data compiled into the project. \u00a0You can do this via Project &gt; Config Properties &gt; Linker &gt; System &gt; Stack (Reserve&amp;Commit) Size &gt; .. I changed them both to 4000000 and things worked.<\/li>\n<\/ol>\n<p><strong>Final packaging<\/strong><\/p>\n<p>I found that running right from VC didn&#8217;t always work. (Maybe I should find out why, but I haven&#8217;t.) \u00a0But I can run from the command-line. \u00a0Before doing so, I needed to:<\/p>\n<ol>\n<li>Copy in required dlls from SDL, etc<\/li>\n<li>Copy in game data files<\/li>\n<li>Copy in the VC Runtime files from: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT<\/li>\n<li>For a release build I&#8217;m sure to build against SDLmain_nostdio.lib so that the game won&#8217;t crash Vista\/Win7 where writing out stdout.txt and stderr.txt may result in some kind of fail.<\/li>\n<\/ol>\n<p><strong>Saving to Your_Favorite_Version_Control_System<\/strong><\/p>\n<ol>\n<li>You may leave out all your &#8216;Debug&#8217; folders or other Configuration folders, those seem to only contain generated files.<\/li>\n<li>You may leave out the .ncb and the .COMPUTER.username.blah file, they seem to be used by VC for stuff that can be regenerated, etc.<\/li>\n<\/ol>\n<p>Hopefully this will be helpful to anyone who does the same thing. \u00a0Between you and me, I found the install of VC 2008 to be pretty nice in comparison to trying to install mingw, which tends to require considerable muscling. \u00a0Also, since everyone provides their libs as MSVC libs, building against those vendor libs is not only easy, but possible. \u00a0(With mingw, many MSVC C++ libs are unusable due to binary incompatibility.)<\/p>\n<p>-Phil<\/p>\n<p><strong>P.S. Adding an Icon to your Project<\/strong><\/p>\n<p>This is pretty easy. \u00a0Add a Project.rc to your project. \u00a0The Project.rc should include this line:<\/p>\n<p>IDI_PROJECT \u00a0 \u00a0 \u00a0 ICON \u00a0 \u00a0 \u00a0 \u00a0 &#8220;path\/to\/icon256.ico&#8221;<\/p>\n<p>You can create an Icon with <a href=\"http:\/\/icofx.ro\/\">IconFX<\/a> .<\/p>\n<p><strong>P.S.S. Creating a windows Installer<\/strong><\/p>\n<p>I&#8217;ve used <a href=\"http:\/\/www.jrsoftware.org\/isinfo.php\">Innosetup<\/a> in the past. \u00a0It seems to work.<\/p>\n<p><strong>P.S.S.S. Dealing with LPCTSTR conversions<\/strong><\/p>\n<p>If your whole project is using C-strings, you can go into Project &gt; Properties &gt; Configuration Properties &gt; General &gt; Character Set &gt; and change it to &#8220;Not Set&#8221; so that VC will no longer try and use Unicode strings to some of its functions (like ShellExecute.)<\/p>\n<p><strong>P.S.S.S.S. Dealing with conflicting .obj files<\/strong><\/p>\n<p>If you get a linking error about a bunch of undefined symbols and you have say &#8220;game.c&#8221; and &#8220;game.cpp&#8221; in your project, they are both being compiled down to &#8220;game.obj&#8221; .. To set one of them to compile to a different filename, say &#8220;mygame.obj&#8221;, you need to Right Click &gt; C\/C++ &gt; Output Files &gt; Object File Name &gt; &#8220;$(IntDir)\\mygame.obj&#8221;<\/p>\n<p>Alternately, you can just rename some of your source files so there are no name conflicts by default. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve had to port a project to VC 2008 from my usual mingw setup. \u00a0Here&#8217;s what I did. \u00a0This covers quite a few things, in particular where to find common GCC settings in VC land. Setting up the project New project Type: win32 Template: Win32 console if you want a console. \u00a0Or just Win32 Project [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,6,1],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-c","category-development","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=266"}],"version-history":[{"count":14,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":915,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/266\/revisions\/915"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}