From ed5efaf32de5e1b968898c8d04a7e968a332bf93 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 21 Jan 2024 19:30:22 +0100 Subject: [PATCH] Fix windows build, and windows build docs. --- compile_windows_sfwl.sh | 1 + demos/build_scripts/sfwl/compile_windows.sh | 2 +- sfw/core/typedefs.h | 2 +- sfw/object/array.cpp | 6 ++++ sfwl/core/typedefs.h | 2 +- sfwl/object/array.cpp | 6 ++++ tools/doc/compilation_no_renderer.md.html | 32 +++++++++++++++++++-- tools/merger/sfwl/sfwl_core.cpp.inl | 7 +++-- tools/merger/sfwl/sfwl_full.cpp.inl | 7 +++-- 9 files changed, 55 insertions(+), 10 deletions(-) diff --git a/compile_windows_sfwl.sh b/compile_windows_sfwl.sh index 10c0e9f..0279a9e 100755 --- a/compile_windows_sfwl.sh +++ b/compile_windows_sfwl.sh @@ -61,5 +61,6 @@ ccache g++ -Wall \ sfwl/object/array.o sfwl/object/dictionary.o sfwl/object/ref_ptr.o \ sfwl/object/resource.o \ sfwl/main.o \ + -lShlwapi -lws2_32 \ -o game diff --git a/demos/build_scripts/sfwl/compile_windows.sh b/demos/build_scripts/sfwl/compile_windows.sh index d8d8f4f..aa78c77 100755 --- a/demos/build_scripts/sfwl/compile_windows.sh +++ b/demos/build_scripts/sfwl/compile_windows.sh @@ -4,4 +4,4 @@ g++ -Wall -g -c main.cpp -o main.o # You might need to add -lpthread and/or -latomic depending on your compiler version -g++ -Wall -g sfwl.o main.o -o game +g++ -Wall -g sfwl.o main.o -lShlwapi -lws2_32 -o game diff --git a/sfw/core/typedefs.h b/sfw/core/typedefs.h index f13c6f2..20c5f52 100644 --- a/sfw/core/typedefs.h +++ b/sfw/core/typedefs.h @@ -110,7 +110,7 @@ T *_nullptr() { * Windows badly defines a lot of stuff we'll never use. Undefine it. */ -#ifdef _WIN32 +#if defined(_WIN64) || defined(_WIN32) #undef min // override standard definition #undef max // override standard definition #undef ERROR // override (really stupid) wingdi.h standard definition diff --git a/sfw/object/array.cpp b/sfw/object/array.cpp index 50738ee..ba5fd87 100644 --- a/sfw/object/array.cpp +++ b/sfw/object/array.cpp @@ -411,6 +411,12 @@ Variant Array::pop_at(int p_pos) { return ret; } +#if defined(_WIN64) || defined(_WIN32) +// Windows... +#undef min +#undef max +#endif + Variant Array::min() const { Variant minval; for (int i = 0; i < size(); i++) { diff --git a/sfwl/core/typedefs.h b/sfwl/core/typedefs.h index f13c6f2..20c5f52 100644 --- a/sfwl/core/typedefs.h +++ b/sfwl/core/typedefs.h @@ -110,7 +110,7 @@ T *_nullptr() { * Windows badly defines a lot of stuff we'll never use. Undefine it. */ -#ifdef _WIN32 +#if defined(_WIN64) || defined(_WIN32) #undef min // override standard definition #undef max // override standard definition #undef ERROR // override (really stupid) wingdi.h standard definition diff --git a/sfwl/object/array.cpp b/sfwl/object/array.cpp index 50738ee..ba5fd87 100644 --- a/sfwl/object/array.cpp +++ b/sfwl/object/array.cpp @@ -411,6 +411,12 @@ Variant Array::pop_at(int p_pos) { return ret; } +#if defined(_WIN64) || defined(_WIN32) +// Windows... +#undef min +#undef max +#endif + Variant Array::min() const { Variant minval; for (int i = 0; i < size(); i++) { diff --git a/tools/doc/compilation_no_renderer.md.html b/tools/doc/compilation_no_renderer.md.html index 955e315..7ea20bc 100644 --- a/tools/doc/compilation_no_renderer.md.html +++ b/tools/doc/compilation_no_renderer.md.html @@ -8,15 +8,20 @@ without any special setting, but if your compiler is older (or set differently) ## IDE Setup -If you use an ide, just add these files to your project (so the .cpp file gets compiled), and you are done. +If you use an ide, add these files to your project (so the .cpp file gets compiled). + +If you are using MingW (If you use the g++ command on windows, that is MingW!), then +find a section in your ide that says something similar to `link to libraries`. Usually +is't under a linker settings section, and add the following entries: `Shlwapi`, `ws2_32`. + +If you use anything else, you are done. ## Manual setup -### g++ / mingw +### g++ - Linux / OSX If you are using a compiler directly, then just add `sfw.cpp` or `sfwl.cpp` to the list of files that you are compiling: - ``` g++ -g sfw.cpp main.cpp -o prog ``` @@ -32,6 +37,27 @@ g++ -g -c main.cpp -o main.o g++ -g sfw.o main.o -o prog ``` +### g++ / mingw - Windows + +If you are using a compiler directly, then add `sfw.cpp` or `sfwl.cpp` to the list of files that you are compiling, +and link to `lShlwapi` and `ws2_32`: + + +``` +g++ -g sfw.cpp main.cpp -lShlwapi -lws2_32 -o prog +``` + +Note: -g means add debug information to the executable. + +If you are creating object files: + +``` +g++ -g -c sfw.cpp -o sfw.o +g++ -g -c main.cpp -o main.o + +g++ -g sfw.o main.o -lShlwapi -lws2_32 -o prog +``` + ### MSVC If you are using a compiler directly, then just add `sfw.cpp` or `sfwl.cpp` to the list of files that you are compiling: diff --git a/tools/merger/sfwl/sfwl_core.cpp.inl b/tools/merger/sfwl/sfwl_core.cpp.inl index d1d6076..58815ed 100644 --- a/tools/merger/sfwl/sfwl_core.cpp.inl +++ b/tools/merger/sfwl/sfwl_core.cpp.inl @@ -13,14 +13,17 @@ #include #include #include -#include #include -#include #include #include #include #include +#if !defined(_WIN64) && !defined(_WIN32) +#include +#include +#endif + #ifndef SFWL_H #include "sfwl.h" #endif diff --git a/tools/merger/sfwl/sfwl_full.cpp.inl b/tools/merger/sfwl/sfwl_full.cpp.inl index 4c9c41e..bf3d9e1 100644 --- a/tools/merger/sfwl/sfwl_full.cpp.inl +++ b/tools/merger/sfwl/sfwl_full.cpp.inl @@ -13,14 +13,17 @@ #include #include #include -#include #include -#include #include #include #include #include +#if !defined(_WIN64) && !defined(_WIN32) +#include +#include +#endif + #ifndef SFWL_H #include "sfwl.h" #endif