Quick start
Quick start
This tutorial walks you through downloading the SpaceAST binary release and building your first program.
Requirements
Before you start, make sure a C++ compiler is installed.
- Windows: Visual Studio (MSVC) is the usual choice. Select the "Desktop development with C++" workload during installation.
- Linux: GCC is usually preinstalled. If it is not, run
sudo apt install build-essential(Ubuntu/Debian).
The tutorial also uses a build tool later. If you are unsure which one to pick, follow the default recommendation in each section.
Download
Go to the releases page and download the binary package for your operating system.
On Windows
1. Extract
Extract the downloaded zip to any directory (for example D:\SpaceAST). The examples below assume D:\SpaceAST, with this layout:
D:\SpaceAST
├── bin/ # dynamic libraries (.dll)
├── include/ # headers
├── lib/ # import libraries (.lib)
└── examples/ # example code2. Create a project and write code
Create a new directory as the project root (for example D:\my_project), next to SpaceAST, and add a file named hello_ast.cpp:
// hello_ast.cpp
#include "ast/DateTime.hpp"
#include "ast/JulianDate.hpp"
#include <iostream>
int main() {
AST_USING_NAMESPACE
// Build a Julian date from a calendar date
JulianDate jd = JulianDate::FromDateTime(2025, 1, 1, 0, 0, 0.0);
std::cout << "JD: " << jd.impreciseDay() << std::endl;
// Convert the Julian date back to a date-time
DateTime dt = DateTime::FromJD(jd);
std::cout << "DateTime: " << dt.toString() << std::endl;
return 0;
}3. Build
Pick any of the following build methods:
- Open Visual Studio, choose File → New → Project, select C++ Console App, set the location to
D:\my_project, and click Create. - In Solution Explorer, right-click the project → Add → Existing Item and select the
hello_ast.cppyou just created. - Right-click the project → Properties and configure:
- C/C++ → General → Additional Include Directories: add
D:\SpaceAST\include - Linker → General → Additional Library Directories: add
D:\SpaceAST\lib - Linker → Input → Additional Dependencies: add
AstCore.lib;AstUtil.lib;AstMath.lib
Tips
This is the Release configuration. To build in Debug, switch Configuration at the top of the property pages to Debug, then use
AstCore_d.lib;AstUtil_d.lib;AstMath_d.lib(library names carry the_dsuffix). - C/C++ → General → Additional Include Directories: add
- Copy every
.dllunderD:\SpaceAST\bin\to the output directory.
The output directory depends on your project settings, usuallyD:\my_project\x64\Release\orD:\my_project\x64\Debug\.
If you are unsure, check Linker → General → Output Directory in the project properties.Tips
Alternatively, add
D:\SpaceAST\bin\to the systemPATH. - Press
Ctrl+F5, or choose Debug → Start Without Debugging, to build and run.
- Install CMake from cmake.org (select "Add to PATH" during installation).
- Create a
CMakeLists.txtinD:\my_project:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HelloAst)
set(AST_HOME "D:/SpaceAST" CACHE PATH "SpaceAST install path")
include_directories(${AST_HOME}/include)
link_directories(${AST_HOME}/lib)
add_executable(hello_ast hello_ast.cpp)
# Debug links the _d-suffixed libraries; Release links the plain names
target_link_libraries(hello_ast
debug AstCore_d AstUtil_d AstMath_d
optimized AstCore AstUtil AstMath
)- Open a terminal (PowerShell or cmd) in the project directory and run:
Opening a terminal
Type
cmdin the address bar of theD:\my_projectfolder and press Enter.
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022"
cmake --build . --config Release- Copy
D:\SpaceAST\bin\*.dllto the output directory (usuallyD:\my_project\build\Release\) and run:
.\Release\hello_ast.exe- Install xmake: see the xmake documentation.
- Create an
xmake.luainD:\my_project:
-- xmake.lua
add_rules("mode.release", "mode.debug")
target("hello_ast")
set_kind("binary")
add_files("hello_ast.cpp")
-- Add library paths (replace if SpaceAST is not at ../SpaceAST)
add_includedirs("../SpaceAST/include")
add_linkdirs("../SpaceAST/lib")
-- Link libraries (debug names carry the _d suffix)
if is_mode("debug") then
add_links("AstCore_d", "AstUtil_d", "AstMath_d")
else
add_links("AstCore", "AstUtil", "AstMath")
end- Open a terminal (PowerShell or cmd) in the project directory and run:
Opening a terminal
Type
cmdin the address bar of theD:\my_projectfolder and press Enter.
xmake f -m release
xmake
xmake run hello_astNotes
- Debug library names carry the
_dsuffix (for exampleAstCore_d.dll); Release names do not. - Link the modules your program uses.
AstCore(dynamics),AstMath(math) andAstUtil(utilities) are the three base layers. - The DLLs must be next to the executable or on
PATHat run time.
On Linux
1. Extract
Extract the downloaded tar.gz to any directory (for example /opt/SpaceAST). The examples below assume /opt/SpaceAST, with this layout:
/opt/SpaceAST/
├── include/ # headers
├── lib/ # shared libraries (.so)
└── examples/ # example code2. Create a project and write code
Create a project directory (for example ~/my_project) and add a file named hello_ast.cpp:
// hello_ast.cpp
#include "ast/DateTime.hpp"
#include "ast/JulianDate.hpp"
#include <iostream>
int main() {
AST_USING_NAMESPACE
// Build a Julian date from a calendar date
JulianDate jd = JulianDate::FromDateTime(2025, 1, 1, 0, 0, 0.0);
std::cout << "JD: " << jd.impreciseDay() << std::endl;
// Convert the Julian date back to a date-time
DateTime dt = DateTime::FromJD(jd);
std::cout << "DateTime: " << dt.toString() << std::endl;
return 0;
}3. Build
Pick any of the following build methods:
- Install CMake if it is not already available:
sudo apt install cmake- Create a
CMakeLists.txtin~/my_project:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HelloAst)
set(AST_HOME "/opt/SpaceAST" CACHE PATH "SpaceAST install path")
include_directories(${AST_HOME}/include)
link_directories(${AST_HOME}/lib)
add_executable(hello_ast hello_ast.cpp)
target_link_libraries(hello_ast AstCore AstUtil AstMath)
# Set the runtime library search path
set_target_properties(hello_ast PROPERTIES
INSTALL_RPATH "${AST_HOME}/lib"
BUILD_RPATH "${AST_HOME}/lib"
)- Open a terminal in the project directory and run:
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
./hello_ast- Make sure
makeandg++are installed (usually preinstalled; otherwise runsudo apt install build-essential). - Create a
Makefilein~/my_project:
# Makefile
AST_HOME := /opt/SpaceAST
CXX := g++
CXXFLAGS := -std=c++11 -I$(AST_HOME)/include
LDFLAGS := -L$(AST_HOME)/lib -Wl,-rpath,$(AST_HOME)/lib
LDLIBS := -lAstCore -lAstUtil -lAstMath
hello_ast: hello_ast.cpp
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)- Open a terminal in the project directory and run:
make
./hello_ast- Install xmake: see the xmake documentation.
- Create an
xmake.luain~/my_project:
-- xmake.lua
add_rules("mode.release", "mode.debug")
target("hello_ast")
set_kind("binary")
add_files("hello_ast.cpp")
-- Add library paths (replace if SpaceAST is not at /opt/SpaceAST)
add_includedirs("/opt/SpaceAST/include")
add_linkdirs("/opt/SpaceAST/lib")
add_rpathdirs("/opt/SpaceAST/lib")
add_links("AstCore", "AstUtil", "AstMath")- Open a terminal in the project directory and run:
xmake f -m release
xmake
xmake run hello_astNotes
rpathlets the program find the.sofiles at run time without settingLD_LIBRARY_PATHmanually.
Next steps
Congratulations! You have run your first SpaceAST program.
- Browse the examples for more example code
- Read the module reference to learn what each module does
- See build from source to integrate and build the source yourself
- Check the API reference for the full interface