Compiling the ClusterIO / ThermostatIO Sample Using a Makefile on Windows
If you’ve looked at either the ClusterIO or ThermostatIO samples that ship with Storyboard, you’ll have noticed there is a README file that describes how to build the source for the project.
It describes two approaches to do this:
- Building with a Makefile
- Building with Visual Studio
The Visual Studio approach is very straightforward and will just work right out of the gate as long as you follow the instructions. However the Makefile approach is left purposefully generic because it will change depending on what platform you are building on.
For this article, let’s go over building a Makefile on Windows.
Technically both approaches will need Visual Studio installed, so make sure to have that.
This was performed using the Developer Command Prompt for Visual Studio, as easy access to “cl” was needed.
The full Makefile is as follows:
CC=cl
CFLAGS=/DWIN32 /MD
SB_ROOT="C:/Program Files/Crank_Software_7.1/Storyboard_Engine/7.1-stable.202111011444/win32-x86-opengles_2.0-obj"
SB_INC=/I$(SB_ROOT)/include
SB_LIB=libgreal.lib libgreio.lib legacy_stdio_definitions.lib
LDFLAGS=/LIBPATH:$(SB_ROOT)/lib
all: cluster_update.exe
cluster_update.exe: cluster_update.c
$(CC) $(CFLAGS) $(SB_INC) $^ $(SB_LIB) /link /out:$@ $(LDFLAGS)
Let’s take a closer look at what this is doing.
First let’s set up the compiler and its flags.
CC=cl
CFLAGS=/DWIN32 /MD
Here we specify our compiler as cl which comes with Visual Studio. For CFLAGS we’re passing in the options of DWIN32 because the source sets up different variables depending on the OS.
MD is to bring in the release .dll version of the CRT link libraries within vc\lib.
Next let’s set up some Storyboard variables.
SB_ROOT="C:/Program Files/Crank_Software_7.1/Storyboard_Engine/7.1-stable.202111011444/win32-x86-opengles_2.0-obj"
SB_INC=/I$(SB_ROOT)/include
SB_LIB=libgreal.lib libgreio.lib legacy_stdio_definitions.lib
Your SB_ROOT path may look a bit different than mine of course, but simply point to the runtime that you’re using.
Next you will need to point to your runtime’s include folder.
For now we will just set SB_LIB to the extra libraries that we will need to pull in.
You will see why that is at the end.
LDFLAGS=/LIBPATH:$(SB_ROOT)/lib
Here we use cl’s LIBPATH parameter to specify a path that the linker will search before it searches the path specified in the LIB environment option. In this case that would be our runtime’s lib directory.
Let’s finish with our exports:
all: cluster_update.exe
cluster_update.exe: cluster_update.c
$(CC) $(CFLAGS) $(SB_INC) $^ $(SB_LIB) /link /out:$@ $(LDFLAGS)
This is pretty standard, but the main thing to note here is that we broke up the SB_LIB and LDFLAGS variables to enable us to order them in this way.
Once this is all set, save it out, and place it in the ClusterIO’s "source_code" directory.
This will output the cluster_update.exe file.
You can now simulate the ClusterIO project in Designer, and then execute cluster_update.exe.
You will see that the cluster will begin to update.
Success!
Makefile alternative
Now if you find the Makefile approach a bit heavy-handed for what this is you can simplify it and create a Batch file instead. All you will need to write in the Batch file is:
set SB_ROOT="C:/Program Files/Crank_Software_7.1/Storyboard_Engine/7.1-stable.202111011444/win32-x86-opengles_2.0-obj"
cl /DWIN32 /MD /I%SB_ROOT%/include cluster_update.c libgreal.lib libgreio.lib legacy_stdio_definitions.lib /link /LIBPATH:%SB_ROOT%/lib
Save that out as a .bat and execute it. cluster_update.exe will be successfully generated.
Comments
Please sign in to leave a comment.