STARTcraft icon indicating copy to clipboard operation
STARTcraft copied to clipboard

Linux support

Open vec2pt opened this issue 7 months ago • 2 comments

I made an attempt to compile StarterBot on Linux. Unfortunately I had to make small changes to src to make it work.

1. error: ‘size_t’ does not name a type

x86_64-w64-mingw32-g++ -I./src -I./src/starterbot -I./src/bwapi -I./src/bwapi/include -I./src/bwapi/include/BWAPI -I./src/bwapi/include/BWAPI/Client -I./src/bwapi/BWAPIClient -I./src/bwapi/BWAPILIB -I./src/bwapi/shared -MMD -MP  -c src/starterbot/StarterBot.cpp -o bin_linux/./src/starterbot/StarterBot.cpp.o
In file included from src/starterbot/MapTools.h:3,
                 from src/starterbot/StarterBot.h:3,
                 from src/starterbot/StarterBot.cpp:1:
src/starterbot/Grid.hpp:8:5: error: ‘size_t’ does not name a type
    8 |     size_t m_width = 0;
      |     ^~~~~~
src/starterbot/Grid.hpp:4:1: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
    3 | #include <vector>
  +++ |+#include <cstddef>
    4 | 
src/starterbot/Grid.hpp:9:5: error: ‘size_t’ does not name a type
    9 |     size_t m_height = 0;
      |     ^~~~~~
src/starterbot/Grid.hpp:9:5: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
src/starterbot/Grid.hpp:17:16: error: expected ‘)’ before ‘width’
   17 |     Grid(size_t width, size_t height, T val)
      |         ~      ^~~~~~
      |                )
src/starterbot/Grid.hpp:25:20: error: ‘size_t’ has not been declared
   25 |     inline T & get(size_t x, size_t y)
      |                    ^~~~~~
src/starterbot/Grid.hpp:25:30: error: ‘size_t’ has not been declared
   25 |     inline T & get(size_t x, size_t y)
      |                              ^~~~~~
src/starterbot/Grid.hpp:30:26: error: ‘size_t’ has not been declared
   30 |     inline const T & get(size_t x, size_t y) const
      |                          ^~~~~~
src/starterbot/Grid.hpp:30:36: error: ‘size_t’ has not been declared
   30 |     inline const T & get(size_t x, size_t y) const
      |                                    ^~~~~~
src/starterbot/Grid.hpp:35:21: error: ‘size_t’ has not been declared
   35 |     inline void set(size_t x, size_t y, T val)
      |                     ^~~~~~
src/starterbot/Grid.hpp:35:31: error: ‘size_t’ has not been declared
   35 |     inline void set(size_t x, size_t y, T val)
      |                               ^~~~~~
src/starterbot/Grid.hpp:40:12: error: ‘size_t’ does not name a type
   40 |     inline size_t width() const
      |            ^~~~~~
src/starterbot/Grid.hpp:40:12: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
src/starterbot/Grid.hpp:45:12: error: ‘size_t’ does not name a type
   45 |     inline size_t height() const
      |            ^~~~~~
src/starterbot/Grid.hpp:45:12: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
make: *** [Makefile:30: bin_linux/./src/starterbot/StarterBot.cpp.o] Error 1

The simple solution is to add #include <cstddef> to the ./src/starterbot/Grid.hpp file.

➜ git diff ./src/starterbot/Grid.hpp                                    
diff --git a/src/starterbot/Grid.hpp b/src/starterbot/Grid.hpp
index 196a7d2..d7f2242 100644
--- a/src/starterbot/Grid.hpp
+++ b/src/starterbot/Grid.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <vector>
+#include <cstddef>
 
 template <class T>
 class Grid

2. fatal error: Windows.h: No such file or directory

x86_64-w64-mingw32-g++ -I./src -I./src/starterbot -I./src/bwapi -I./src/bwapi/include -I./src/bwapi/include/BWAPI -I./src/bwapi/include/BWAPI/Client -I./src/bwapi/BWAPIClient -I./src/bwapi/BWAPILIB -I./src/bwapi/shared -MMD -MP  -c src/starterbot/main.cpp -o bin_linux/./src/starterbot/main.cpp.o
In file included from ./src/bwapi/include/BWAPI/Client.h:2,
                 from src/starterbot/main.cpp:2:
./src/bwapi/include/BWAPI/Client/Client.h:9:10: fatal error: Windows.h: No such file or directory
    9 | #include <Windows.h>
      |          ^~~~~~~~~~~
compilation terminated.
make: *** [Makefile:30: bin_linux/./src/starterbot/main.cpp.o] Error 1

This error is solved by replacing #include <Windows.h> by #include <windows.h>.

➜ git diff ./src/bwapi/include/BWAPI/Client/Client.h
diff --git a/src/bwapi/include/BWAPI/Client/Client.h b/src/bwapi/include/BWAPI/Client/Client.h
index 1e0d106..8c6f30b 100644
--- a/src/bwapi/include/BWAPI/Client/Client.h
+++ b/src/bwapi/include/BWAPI/Client/Client.h
@@ -6,7 +6,7 @@
 #include "UnitImpl.h"
 #include "GameTable.h"
 
-#include <Windows.h>
+#include <windows.h>
 
 
 namespace BWAPI

After these two changes, the code compiles without problems (on Linux, unfortunately I have no way to check it on windows). Makefile and instruction can be found in my fork. Remember that you said in one of the videos that you plan to support Linux, I will be happy to pull these changes into your repo. Maybe it's a good idea to create a new branch?

vec2pt avatar Aug 03 '24 21:08 vec2pt