Trouble compiling Angband

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rjphares
    Rookie
    • Dec 2017
    • 4

    Trouble compiling Angband

    I'm on Windows 8.1 using visual studio 2017. I get error: Error C1189 #error: Macro definition of snprintf conflicts with Standard Library function declaration Angband1 c:\program files (x86)\windows kits\10\include\10.0.16299.0\ucrt\stdio.h 1933

    Please help. Thanks.
  • Nick
    Vanilla maintainer
    • Apr 2007
    • 9637

    #2
    Try going into the file src\h-basic.h, removing these lines:
    Code:
    /**
     * Native MSVC compiler doesn't understand inline or snprintf
     */
    #ifdef _MSC_VER
    #	define inline __inline
    #	define snprintf _snprintf
    #endif
    and see what happens.

    Those lines were apparently to deal with deficiencies in the Microsoft compiler which look like they may have been fixed. Let us know how you go.
    One for the Dark Lord on his dark throne
    In the Land of Mordor where the Shadows lie.

    Comment

    • rjphares
      Rookie
      • Dec 2017
      • 4

      #3
      I'm down to 4 errors:

      Error (active) E0028 expression must have a constant value Angband1 c:\Users\Robert\source\repos\Angband1\Angband1\loa d.c 808

      Error C2057 expected constant expression Angband1 c:\users\robert\source\repos\angband1\angband1\loa d.c 808

      Error C2466 cannot allocate an array of constant size 0 Angband1 c:\users\robert\source\repos\angband1\angband1\loa d.c 808

      Error C2133 'itypes': unknown size Angband1 c:\users\robert\source\repos\angband1\angband1\loa d.c 808


      line 808 from load.c looks like:
      Code:
       	bitflag flags, itypes[itype_size];

      Comment

      • Nick
        Vanilla maintainer
        • Apr 2007
        • 9637

        #4
        OK, you can safely replace itype_size with ITYPE_SIZE in that line, which should fix that problem.
        One for the Dark Lord on his dark throne
        In the Land of Mordor where the Shadows lie.

        Comment

        • rjphares
          Rookie
          • Dec 2017
          • 4

          #5
          2 errors:
          Error LNK2001 unresolved external symbol _init_sound_win Angband1 C:\Users\Robert\source\repos\Angband1\Angband1\sou nd-core.obj 1

          Error LNK1120 1 unresolved externals Angband1 C:\Users\Robert\source\repos\Angband1\Debug\Angban d1.exe 1

          I may end up having to start over from the beginning.
          This is what I did since the visual studio instructions are out of date:
          • Added libpng.dll and zlib1.dll to project directory.
          • Added zlib1.lib(no such file, I tried renaming) libpng.lib msimg32.lib winmm.lib to Properties->Linker->Input->Additional Dependencies
          • Added all src ".h" and ".c" files, excluding files with "main" and snd-sdl.c to project directory and project.
          • Added all src\win ".h" and ".c" files to project directory and project.
          • Added all src\win angband.rc and angband.ico files to project directory and project.
          • Added all src\win\include ".h" files to project directory and project.
          • Added main-win.c file to project directory and project.

          Comment

          • rjphares
            Rookie
            • Dec 2017
            • 4

            #6
            I think I'm going to wait to compile until there is an update for visual studio instructions. Thanks for the help.

            Comment

            • Nick
              Vanilla maintainer
              • Apr 2007
              • 9637

              #7
              Sorry, I missed your last post.

              You could try replacing
              Code:
              errr init_sound_win(struct sound_hooks *hooks, int argc, char **argv);
              in src/snd-win.h with
              Code:
              extern errr init_sound_win(struct sound_hooks *hooks, int argc, char **argv);
              from where you were at that point, and see if that works.
              One for the Dark Lord on his dark throne
              In the Land of Mordor where the Shadows lie.

              Comment

              • slimehunter
                Rookie
                • Oct 2020
                • 4

                #8
                Originally posted by Nick
                You could try replacing
                Code:
                errr init_sound_win(struct sound_hooks *hooks, int argc, char **argv);
                in src/snd-win.h with
                Code:
                extern errr init_sound_win(struct sound_hooks *hooks, int argc, char **argv);
                from where you were at that point, and see if that works.
                I'm encountering this issue when compiling, and unfortunately adding the extern prefix did not fix the error.

                Comment

                • backwardsEric
                  Knight
                  • Aug 2019
                  • 527

                  #9
                  Originally posted by slimehunter
                  I'm encountering this issue when compiling, and unfortunately adding the extern prefix did not fix the error.
                  One thing to try would be to either set SOUND in the preprocessor definitions (here's Microsoft's instructions, with the Visual Studio part at the bottom of the page, https://docs.microsoft.com/en-us/cpp...s?view=vs-2019 ; you're looking to set the equivalent of /DSOUND on the command line) or change line 61 of src/sound-core.c from

                  Code:
                  #if (!defined(WIN32_CONSOLE_MODE) && defined(WINDOWS) && !defined(USE_SDL) && !defined(USE_SDL2))
                  to

                  Code:
                  #if (!defined(WIN32_CONSOLE_MODE) && defined(WINDOWS) && !defined(USE_SDL) && !defined(USE_SDL2) && defined(SOUND))

                  Comment

                  • slimehunter
                    Rookie
                    • Oct 2020
                    • 4

                    #10
                    Originally posted by backwardsEric
                    One thing to try would be to either set SOUND in the preprocessor definitions (here's Microsoft's instructions, with the Visual Studio part at the bottom of the page, https://docs.microsoft.com/en-us/cpp...s?view=vs-2019 ; you're looking to set the equivalent of /DSOUND on the command line) or change line 61 of src/sound-core.c from

                    Code:
                    #if (!defined(WIN32_CONSOLE_MODE) && defined(WINDOWS) && !defined(USE_SDL) && !defined(USE_SDL2))
                    to

                    Code:
                    #if (!defined(WIN32_CONSOLE_MODE) && defined(WINDOWS) && !defined(USE_SDL) && !defined(USE_SDL2) && defined(SOUND))
                    That worked! Thank you!!
                    I'm also getting a few other errors similar to the previous one, but I'll see if I can work around these. Here are the other errors for reference:

                    Code:
                    Severity	Code	Description	Project	File	Line	Suppression State
                    Error	LNK2019	unresolved external symbol _FreeDIB referenced in function _Term_xtra_win_react	angband_win_test2	\main-win.obj	1	
                    Error	LNK2019	unresolved external symbol _ReadDIB2_PNG referenced in function _init_graphics	angband_win_test2	\main-win.obj	1	
                    Error	LNK2019	unresolved external symbol _default_layout_win referenced in function _load_prefs	angband_win_test2	\main-win.obj	1	
                    Error	LNK2019	unresolved external symbol _SaveWindow_PNG referenced in function _process_menus	angband_win_test2	\main-win.obj	1	
                    Error	LNK2019	unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)	angband_win_test2	\MSVCRTD.lib(exe_main.obj)	1

                    Comment

                    • backwardsEric
                      Knight
                      • Aug 2019
                      • 527

                      #11
                      Originally posted by slimehunter
                      That worked! Thank you!!
                      I'm also getting a few other errors similar to the previous one, but I'll see if I can work around these. Here are the other errors for reference:

                      Code:
                      Severity	Code	Description	Project	File	Line	Suppression State
                      Error	LNK2019	unresolved external symbol _FreeDIB referenced in function _Term_xtra_win_react	angband_win_test2	\main-win.obj	1	
                      Error	LNK2019	unresolved external symbol _ReadDIB2_PNG referenced in function _init_graphics	angband_win_test2	\main-win.obj	1	
                      Error	LNK2019	unresolved external symbol _default_layout_win referenced in function _load_prefs	angband_win_test2	\main-win.obj	1	
                      Error	LNK2019	unresolved external symbol _SaveWindow_PNG referenced in function _process_menus	angband_win_test2	\main-win.obj	1	
                      Error	LNK2019	unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)	angband_win_test2	\MSVCRTD.lib(exe_main.obj)	1
                      For all but the last one, did you add the .c and .h files from src\win to the project? FreeDIB(), ReadDIB2_PNG, default_layout_win(), and SaveWindow_PNG() are defined in those files (src\win\readdib.c , src\win\readpng.c , src\win\win-layout.c , and src\win\scrnshot.c ).

                      The last one is likely due to the choice of the project type. This question and the posted answers at StackOverflow, https://stackoverflow.com/questions/...nction-int-cde , may help with that.

                      Comment

                      • slimehunter
                        Rookie
                        • Oct 2020
                        • 4

                        #12
                        Originally posted by backwardsEric
                        For all but the last one, did you add the .c and .h files from src\win to the project? FreeDIB(), ReadDIB2_PNG, default_layout_win(), and SaveWindow_PNG() are defined in those files (src\win\readdib.c , src\win\readpng.c , src\win\win-layout.c , and src\win\scrnshot.c ).

                        The last one is likely due to the choice of the project type. This question and the posted answers at StackOverflow, https://stackoverflow.com/questions/...nction-int-cde , may help with that.
                        Wow, facepalm. That works, it's built now. Thank you! I feel embarrassed now, but I'm realized I think I skipped it when following the step-by-step guide because when I realized steps 9-11 were unnecessary to build/pointing to the wrong directories, my brain just glossed over step 12 too.

                        Anyway, thank you again. I'm on my way to poking around with the code now.


                        Edit: Funny story, it turns out that running the executable that was built results in this weird error message
                        Code:
                        ---------------------------
                        牅潲r
                        ---------------------------
                        慃湮瑯映湩⁤敲畱物摥搠物捥潴祲਺汉扩\
                        ---------------------------
                        OK   
                        ---------------------------
                        From which google translate gives me:
                        Code:
                        ---------------------------
                        牅潲r
                        ---------------------------
                        慃湮瑯映湩Knock on the leftovers 摥搠物捥潴祲han expansion\
                        ---------------------------
                        OK
                        ---------------------------
                        Last edited by slimehunter; October 24, 2020, 19:06.

                        Comment

                        • backwardsEric
                          Knight
                          • Aug 2019
                          • 527

                          #13
                          Originally posted by slimehunter
                          Edit: Funny story, it turns out that running the executable that was built results in this weird error message
                          Code:
                          ---------------------------
                          牅潲r
                          ---------------------------
                          慃湮瑯映湩敲畱物摥搠物捥潴祲਺汉扩\
                          ---------------------------
                          OK   
                          ---------------------------
                          From what I see in Microsoft's documentation, the Win32 API switches from expecting ANSI encoded strings to 16-bit encoded character strings if the UNICODE preprocessor macro is set. It looks like the project settings in src\win\vs2019 don't set that macro. Is it possible that when you set up your project that it set UNICODE by default? That could explain the garbled message and getting rid of UNICODE and then recompiling would get you an executable that produced interpretable messages.

                          Besides the SOUND preprocessor macro you ran into earlier, another macro that appears in the src\win\vs2019 project settings but isn't mentioned in angband_visual_studio_step_by_step.txt is USE_PRIVATE_PATHS - that affects where things like the save file and high score file are placed. For the record, here are the preprocessor macros set in src\win\vs2019\Angband.vcxproj :

                          Code:
                          SOUND;USE_PRIVATE_PATHS;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;

                          Comment

                          • slimehunter
                            Rookie
                            • Oct 2020
                            • 4

                            #14
                            Originally posted by backwardsEric
                            From what I see in Microsoft's documentation, the Win32 API switches from expecting ANSI encoded strings to 16-bit encoded character strings if the UNICODE preprocessor macro is set. It looks like the project settings in src\win\vs2019 don't set that macro. Is it possible that when you set up your project that it set UNICODE by default? That could explain the garbled message and getting rid of UNICODE and then recompiling would get you an executable that produced interpretable messages.

                            Besides the SOUND preprocessor macro you ran into earlier, another macro that appears in the src\win\vs2019 project settings but isn't mentioned in angband_visual_studio_step_by_step.txt is USE_PRIVATE_PATHS - that affects where things like the save file and high score file are placed. For the record, here are the preprocessor macros set in src\win\vs2019\Angband.vcxproj :

                            Code:
                            SOUND;USE_PRIVATE_PATHS;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;
                            ...Oh heck, I didn't even realize that ANSI was required. That was it!
                            I just set the character set project option to multi byte from unicode and that seemed to fix the exe.

                            Thank you!

                            Comment

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