Visual Studio 2010 Express, help for the newbie?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chud
    Swordsman
    • Jun 2010
    • 309

    Visual Studio 2010 Express, help for the newbie?

    Hi,

    Anyone reasonably (or probably only a little) experienced with MS Visual Studio? I'm new to it and having a hard time getting it to behave reasonably. The answer to some of my problems is probably "RTFM" but I have made some attempts to do that ahead of time. :-)

    I created a new project using "Create project from existing source code" using the current angband tree. I can't seem to get the "Solution Explorer" to show the underlying file tree though; it shows all the source files together, and all the header files together, and so when you have files with the same name in different directories they all appear together - and it's not clear how to tell which is which even if this was a good idea:



    Relatedly, probably, I'm having trouble building it in part because it can't find header files it needs. I can solve many of these by manually adding each directory in src/*/ to its include path, but this is hardly portable in addition to being very much a pain. There must be a more general way to do this...

    Any pointers and tip and tricks would be welcome!

    Thanks,
    -C
  • Antoine
    Ironband/Quickband Maintainer
    • Nov 2007
    • 1010

    #2
    I can't help you on this because the NPP files are not split between directories in the way that the Vanilla ones are, so I've not had to deal with the problem. (And am far from an expert anyway)

    A.
    Ironband - http://angband.oook.cz/ironband/

    Comment

    • konijn_
      Hellband maintainer
      • Jul 2007
      • 367

      #3
      Originally posted by Chud
      Hi,

      Anyone reasonably (or probably only a little) experienced with MS Visual Studio? I'm new to it and having a hard time getting it to behave reasonably. The answer to some of my problems is probably "RTFM" but I have made some attempts to do that ahead of time. :-)

      I created a new project using "Create project from existing source code" using the current angband tree. I can't seem to get the "Solution Explorer" to show the underlying file tree though; it shows all the source files together, and all the header files together, and so when you have files with the same name in different directories they all appear together - and it's not clear how to tell which is which even if this was a good idea:



      Relatedly, probably, I'm having trouble building it in part because it can't find header files it needs. I can solve many of these by manually adding each directory in src/*/ to its include path, but this is hardly portable in addition to being very much a pain. There must be a more general way to do this...

      Any pointers and tip and tricks would be welcome!

      Thanks,
      -C
      I have mentioned that MVSC2010 is pretty much broken right now.

      * Things to do that I know off
      * right click on the project, click config properties, c/c++, general, additional include directories, add the src folder since header files are located there for code files in subdirectories
      * Still under c/c++, click on Command Line, make sure the following switch is in there : /D "_WINDOWS"
      * At some point there will be confusion with include dirent/direct.. I think I just used the POSIX direct ( I posted about this ) and did the same as OSX, this compiled better ( as in I got stuck somewhere else )
      * I Got rid of the test code folder when I imported files since it failed miserably, myshkin has added some more files on April 27, so your mileage may vary

      In the end this all didnt work for me still, somehow the externs in externs.h didnt jive with the linker and all references to functions with char or char* died... There is a stackoverflow post on this, but at that point I was ready to kill somebody and with my latent heart condition I decided to just give up and play some more EVE.

      T.
      * Are you ready for something else ? Hellband 0.8.8 is out! *

      Comment

      • Blue Baron
        Adept
        • Apr 2011
        • 103

        #4
        I use VC++ 6.0, so some of the terminology will be different, but what I do is start with a new, blank win32 project. Next rename src/player/util.c to putil.c. Then I add all of the .c and .h files in the src directory to the project except those that have main in their name and snd-sdl.c. Then I add all of the .c and .h files in the player, object, monster, and win directories. Then I add src/main-win.c to the project. Next I add the additional include directories: src, src\player, src\object, src\monster, src\win, src\win\include. Then you need to add the library modules src\win\lib\libpng.lib and src\win\lib\zlib.lib. Finally I save the project and can start compiling.

        Here things will probably get very different. Because I use VC++6.0 I am using an older Win32 SDK and compiler. So I also have to remove the extra const on line 74 of externs.h.

        In z-queue.h I have to remove the line: #include <stdint.h>and replace it with: typedef unsigned int * uintptr_t;

        In generate.c I have to comment out the defines of ROOM_DEBUG and ROOM_LOG, and replace where they are used with the code of the macro. (I have to replace "ROOM_LOG(" with "if (OPT(cheat_room)) msg(".)

        In cmd4.c I need to replace snprintf with strnfmt.

        Lastly, in main-win.c I have to replace GetWindowLongPtr with GetWindowLong, replace SetWindowLongPtr with SetWindowLong and GWLP_USERDATA with GWL_USERDATA.

        If the projects in the other thread don't help, I hope this does.

        Edit: changed the png include directory and libs above to match angband.

        Another Edit: As APWhite says below, the library module winmm.lib also needs to be added. Also, the resource file (src/win/angband.rc) needs to be added to the project.
        Last edited by Blue Baron; June 14, 2011, 20:05.

        Comment

        • d_m
          Angband Devteam member
          • Aug 2008
          • 1517

          #5
          Originally posted by Blue Baron
          I use VC++ 6.0, so some of the terminology will be different, but what I do is start with a new, blank win32 project. Next rename src/player/util.c to putil.c. Then I add all of the .c and .h files in the src directory to the project except those that have main in their name and snd-sdl.c. Then I add all of the .c and .h files in the player, object, monster, and win directories. Then I add src/main-win.c to the project. Next I add the additional include directories: src, src\player, src\object, src\monster, src\win, src\win\libpng. Then I add the library module src\win\libpng\libpng_d.lib. Finally I save the project and can start compiling.

          Here things will probably get very different. Because I use VC++6.0 I am using an older Win32 SDK and compiler. So I also have to remove the extra const on line 74 of externs.h.

          In z-queue.h I have to remove the line: #include <stdint.h>and replace it with: typedef unsigned int * uintptr_t;

          In generate.c I have to comment out the defines of ROOM_DEBUG and ROOM_LOG, and replace where they are used with the code of the macro. (I have to replace "ROOM_LOG(" with "if (OPT(cheat_room)) msg(".)

          In cmd4.c I need to replace snprintf with strnfmt.

          Lastly, in main-win.c I have to replace GetWindowLongPtr with GetWindowLong, replace SetWindowLongPtr with SetWindowLong and GWLP_USERDATA with GWL_USERDATA.

          If the projects in the other thread don't help, I hope this does.

          Edit: my png headers/libraries are in a different strucrure. you would want to use src\win\include and src\win\lib, and copy the dlls to the angband directory.
          Is there a good #define that we could use to do some of these things for you via macros? I feel bad that you have to make so many source modifications to get things going...
          linux->xterm->screen->pmacs

          Comment

          • Blue Baron
            Adept
            • Apr 2011
            • 103

            #6
            Originally posted by d_m
            Is there a good #define that we could use to do some of these things for you via macros? I feel bad that you have to make so many source modifications to get things going...
            That macro is only used in 3 spots, so it is a minor change for me. Overall I think I only changed 20-25 lines of code. I do not think it would be worth supporting a flag for that. Also, I consider it a price of my preference for VC++6.0 rather than one of the later Visual Studios. (well not wanting to buy the professional version of them.)

            Edit: I guess the only changes that I would ask for are to remove the extra? const from line 74 of externs.h and change the snprintf's in cmd4.c to strnfmt's. snprintf is only used 3 times in cmd4.c and once in main-crb.c. strnfmt is used around 330 times?

            Also, I think the following lines should be removed from hook_quit() in main-win.c since they are also in cleanup_angband():
            string_free(ANGBAND_DIR_XTRA_FONT);
            string_free(ANGBAND_DIR_XTRA_GRAF);
            string_free(ANGBAND_DIR_XTRA_SOUND);
            string_free(ANGBAND_DIR_XTRA_HELP);

            The memory is freed, but is not set to NULL, so it gives an exception for me the second time in cleanup_angband.

            Actually these strings are initialized in two places as well in init_stuff() in main-win.c and init_file_paths() in init2.c. Is this a memory leak? maybe only initialize them in main-win.c if they are NULL?
            Last edited by Blue Baron; June 14, 2011, 05:22.

            Comment

            • Chud
              Swordsman
              • Jun 2010
              • 309

              #7
              Thanks - I will continue to experiment with MSVC, but so far it has been both frustrating and unproductive. I was able to get a clean, running compile in about 30 minutes with Eclipse and MinGW (all 30 minutes getting the eclipse settings correct; no code adjustments needed).

              I'm disinclined to change the organizational structure of the directory tree if I can avoid it, in the interest of making it as simple as possible to keep repositories in sync, but it remains to be seen whether I get get MSVC to agree with me on that point.

              Comment

              • APWhite
                Adept
                • Jul 2007
                • 244

                #8
                Originally posted by Chud
                Thanks - I will continue to experiment with MSVC, but so far it has been both frustrating and unproductive. I was able to get a clean, running compile in about 30 minutes with Eclipse and MinGW (all 30 minutes getting the eclipse settings correct; no code adjustments needed).

                I'm disinclined to change the organizational structure of the directory tree if I can avoid it, in the interest of making it as simple as possible to keep repositories in sync, but it remains to be seen whether I get get MSVC to agree with me on that point.

                I use MSVC for all my angand stuff. I use VS2008.
                I wrote up a step by step a few months back.

                Creating a VS2008 Project using the borg and the official release.
                1. Download the game source code
                2. Download the borg source then unzip it into the \src directory.
                3. Create a new project using VS2008
                4. Exclude from the project the directories gtk, nds, osx. And the "main-???" files except main-win.c
                5. Project -> Angband Properties -> Configuration Properties -> C/C++ -> Code Generation -> Run Time Library -> /MT
                6. Project -> Angband Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> winmm.lib
                7. Project -> Angband Properties -> Configuration Properties -> General -> Common Language Runtime Support -> No CLR
                8. Edit config.h line 100. Remove the comments to #define ALLOW_BORG
                9. Rename player\util.c to player\p-util.c
                10. Remove the "main" entry point from Project -> Angband Properties -> Configuration Properties -> Linker -> Advanced -> Entry Point

                Try these steps and let me know how you do. I should be able to walk you through the process.
                St George Chiropractor
                Angband Borg Homepage

                Comment

                • Blue Baron
                  Adept
                  • Apr 2011
                  • 103

                  #9
                  Originally posted by Chud
                  Thanks - I will continue to experiment with MSVC, but so far it has been both frustrating and unproductive. I was able to get a clean, running compile in about 30 minutes with Eclipse and MinGW (all 30 minutes getting the eclipse settings correct; no code adjustments needed).

                  I'm disinclined to change the organizational structure of the directory tree if I can avoid it, in the interest of making it as simple as possible to keep repositories in sync, but it remains to be seen whether I get get MSVC to agree with me on that point.
                  You should not have to make code changes? I had to make them because I use an older win32 sdk and compiler.

                  The directory structure does not need to be changed, except to rename src/player/util.c to src/player/putil.c or something. Its just that I have static png libraries that I built myself, and use, and forgot to change the paths in my post.

                  I think a recent Visual Studio user only needs to be careful about which files are added to the project, the include directories, and the png libraries.

                  Also, the "Solution Explorer" only shows files that have been added to the project, rather than the actual directories.

                  Anyways, all this is for whatever development environment you want to use, so use whatever you are comfortable with and works for you.

                  Comment

                  • jens
                    Swordsman
                    • Apr 2011
                    • 348

                    #10
                    Originally posted by Chud
                    I was able to get a clean, running compile in about 30 minutes with Eclipse and MinGW (all 30 minutes getting the eclipse settings correct; no code adjustments needed).
                    This is exactly what I want as well :-) Chud, could you write up a step by step procedure for me? Did you use the project files Magnate posted?

                    Comment

                    • Chud
                      Swordsman
                      • Jun 2010
                      • 309

                      #11
                      Sure, be happy to, though I'll wait until I get home and can take some screen shots from eclipse - that'll probably make things clearer.

                      Comment

                      • Blue Baron
                        Adept
                        • Apr 2011
                        • 103

                        #12
                        Originally posted by d_m
                        Is there a good #define that we could use to do some of these things for you via macros? I feel bad that you have to make so many source modifications to get things going...
                        I have been reading about the changes I made. I still think that the extra const in line 74 of externs.h should be removed and the snprintf calls should changed to strnfmt (or strnfmt calls changed to snprintf). But for the rest I have reverted my changes and added some defines.

                        In z-queue.h I changed the include line to:
                        Code:
                        /* MSVC doesn't have stdint.h (which is C99), so we'll just
                         create the right pointer manually */
                        #ifdef _MSC_VER
                        #ifdef _WIN64
                        typedef unsigned _int64 * uintptr_t // I do not know what should be here
                        #else
                        typedef unsigned int * uintptr_t
                        #endif
                        #else
                        #include <stdint.h>
                        #endif
                        This is based on a section at the bottom of defines.h and that wikepedia says that VS2010 does not support C99.

                        In main-win.c I added the following below #if (defined(WINDOWS) && !defined(USE_SDL)):
                        Code:
                        #ifndef GetWindowLongPtr
                        #define GetWindowLongPtr GetWindowLong
                        #endif
                        #ifndef SetWindowLongPtr
                        #define SetWindowLongPtr SetWindowLong
                        #endif
                        #ifndef GWLP_USERDATA
                        #define GWLP_USERDATA GWL_USERDATA
                        #endif
                        I have not tested this in a recent Visual Studio, so I do not know
                        if it will work (that it will skip all of the defines), but it works for me in VC++ 6.0.

                        For the variadic macros in generate.c (which are C99 as well) the following compiles for me:
                        Code:
                        #if __STDC_VERSION__ < 199901L
                        #define ROOM_LOG if (OPT(cheat_room)) msg
                        #else
                        #define ROOM_LOG(...) if (OPT(cheat_room)) msg(__VA_ARGS__);
                        #endif
                        but I have not enabled the cheat_room option to make sure that it works.

                        BTW, snprintf is C99 as well.

                        Edit: all of this is for the June 10th nightly.
                        Last edited by Blue Baron; June 14, 2011, 19:43.

                        Comment

                        • APWhite
                          Adept
                          • Jul 2007
                          • 244

                          #13
                          Did anyone ever get a solution to compile and work for VS2010 or VS2008. I am still stuck in limbo. I can get my 330 to compile but it won't run. There are errors in the .exe file. I had to do a whole bunch of tinkering on the source to get it to work.

                          I'd be happy if someone sent me a working Vanilla340 solution for VS2008 or VS2010. Maybe then, I can update the borg.

                          andrew@innovapain.com
                          St George Chiropractor
                          Angband Borg Homepage

                          Comment

                          Working...
                          😀
                          😂
                          🥰
                          😘
                          🤢
                          😎
                          😞
                          😡
                          👍
                          👎