Login Page - Create Account

Support Board


Date/Time: Mon, 16 Sep 2024 19:11:21 +0000



[Programming Help] - cross compile from macos targeting both aarch64 and x86_64

View Count: 226

[2024-07-28 18:08:34]
seandunaway - Posts: 266
this was a proper headache, so i'll post it here for posterity

just place this makefile in the directory with your .cpp files and type make for easy sierrachart compatible aarch64 and x86_64 dlls

makefile
scmake = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

llvm ?= https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.0-rc2/LLVM-19.1.0-rc2-macOS-ARM64.tar.xz
xwin ?= https://github.com/Jake-Shadle/xwin/releases/download/0.6.5/xwin-0.6.5-aarch64-apple-darwin.tar.gz
sc ?= https://download2.sierrachart.com//downloads/ZipFiles/SierraChart2600.zip

destdir ?= ~/.wine/drive_c/SierraChart/Data/ /Volumes/[C]%Windows%11/SierraChart/Data/
host ?= localhost windows-11

CXX = $(scmake)llvm/bin/clang++
CXXFLAGS += -target $(arch)-pc-windows-msvc -O3 -shared -fuse-ld=lld
CXXFLAGS += -Weverything -Wno-missing-prototypes
CXXFLAGS += $(addprefix -isystem, $(header))
LDFLAGS += $(addprefix -L, $(addsuffix /$(arch), $(library)))
LDLIBS += -lgdi32

header += $(scmake)xwin/splat/crt/include
header += $(shell find $(scmake)xwin/splat/sdk/include -maxdepth 1 -type d)
header += $(scmake)sc/ACS_Source
library += $(scmake)xwin/splat/crt/lib
library += $(shell find $(scmake)xwin/splat/sdk/lib -maxdepth 1 -type d)

src = $(wildcard *.cpp)
aarch64 = $(src:.cpp=_arm64.dll)
x86_64 = $(src:.cpp=_64.dll)

default: dependency aarch64 x86_64

aarch64: arch = aarch64
aarch64: $(aarch64)
%_arm64.dll: %.cpp
  $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
  rm $*_arm64.lib

x86_64: arch = x86_64
x86_64: $(x86_64)
%_64.dll: %.cpp
  $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
  rm $*_64.lib

clean:
  rm -f $(aarch64) $(aarch64:.dll=.lib) $(aarch64:.dll=.pdb) $(x86_64) $(x86_64:.dll=.lib) $(x86_64:.dll=.pdb)

install: $(aarch64) $(x86_64)
  $(foreach dir, $(destdir), $(foreach dll, $^, cp $(dll) $(subst %,\ , $(dir));))

uninstall: unload
  $(foreach dir, $(destdir), cd $(subst %,\ ,$(dir)) && rm -f $(aarch64) $(x86_64);)

unload:
  $(foreach h, $(host), scdll -a $(h) unload;)

load:
  $(foreach h, $(host), scdll -a $(h) load;)

reload: unload install load

dependency: $(scmake)llvm $(scmake)xwin $(scmake)sc

$(scmake)llvm:
  curl -Ls $(llvm) > $@.tar.xz
  mkdir $@
  tar -xf $@.tar.xz -C $@ --strip-components=1
  rm $@.tar.xz

$(scmake)xwin:
  curl -Ls $(xwin) > $@.tar.gz
  mkdir $@
  tar -zxf $@.tar.gz -C $@ --strip-components=1
  rm $@.tar.gz
  $@/xwin --accept-license --arch aarch64,x86_64 --cache-dir $@ --sdk-version 10.0.22621 splat --disable-symlinks --include-debug-libs --include-debug-symbols

$(scmake)sc:
  curl -Ls $(sc) > $@.zip
  mkdir $@
  unzip -q $@.zip -d $@
  rm $@.zip

purge:
  rm -rf $(scmake)llvm $(scmake)xwin $(scmake)sc $(scmake)llvm.tar.xz $(scmake)xwin.tar.gz $(scmake)sc.zip

.PHONY: default aarch64 x86_64 clean install uninstall unload load reload dependency purge

Date Time Of Last Edit: 2024-08-22 03:16:24
imageaddstudy.png / V - Attached On 2024-08-21 05:02:08 UTC - Size: 42.14 KB - 13 views
[2024-08-04 20:17:22]
gtaranti - Posts: 63
Thanks for posting this...

I'm using VS 2022 Build tools to compile both x86_64 and aarch64, each one in its own environment.


After installing VS 2022 Build tools my script for aarch64 is :

SET FILENAME=gt_trading

powershell -Command "$client = New-Object System.Net.Sockets.UdpClient; $bytes = [System.Text.Encoding]::ASCII.GetBytes('RELEASE_DLL--C:\SierraChart\Data\%FILENAME%_arm64.dll'); $client.Send($bytes, $bytes.Length, 127.0.0.1, 22093); $client.Close();"


powershell -Command "Start-Sleep -Seconds 1"

call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86_arm64
cl /I "C:\Program Files\libpqxx\include" /I "C:/Users/gt/src/vcpkg/installed/arm64-windows/include" /JMC /MP /analyze- /Zc:wchar_t /Z7 /Od /GS /W3 /RTC1 /Zc:inline /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /MD /Gd /Gy /GR- /GF /fp:precise /std:c++20 /LD /EHa /WX- /diagnostics:classic /nologo /Fo:"C:\SierraChart\ACS_Source\%FILENAME%.obj" "C:\SierraChart\ACS_Source\%FILENAME%.cpp" /link /NODEFAULTLIB:library "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "libpq.lib" "pqxx.lib" "ws2_32.lib" "wsock32.lib" /DLL /DYNAMICBASE /DEBUG /INCREMENTAL:NO /OPT:REF /MACHINE:ARM64 /LIBPATH:"C:\Program Files\libpqxx\lib" /LIBPATH:"C:\Program Files\PostgreSQL\15\lib" /TLBID:1 /OUT:"C:\SierraChart\Data\%FILENAME%_arm64.dll"


powershell -Command "$client = New-Object System.Net.Sockets.UdpClient; $bytes = [System.Text.Encoding]::ASCII.GetBytes('ALLOW_LOAD_ALL_DLLS'); $client.Send($bytes, $bytes.Length, 127.0.0.1, 22093); $client.Close();"

It's also sending UDP packets to SC to Release DLL and Allow loading DLL, in order to perform an in place change without the need to manually release/allow dlls or restart SC.
I'm using also some external *.lib files ("libpq.lib" "pqxx.lib") for postgresql database integration.

The x86_64 script has different compiler/linker options but is similar in structure.
[2024-08-05 03:58:40]
seandunaway - Posts: 266
very cool and great idea reloading via udp right in the build script! thanks for sharing
Date Time Of Last Edit: 2024-08-05 03:59:00
[2024-08-05 06:26:12]
gtaranti - Posts: 63
Credits for the idea of udp reloading go to Clion Run/Debug Config Template attached

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account