Build on MacOS - #91
Open
murilobalves wants to merge 1 commit into
Open
Conversation
fernandohds564
approved these changes
Jul 28, 2026
fernandohds564
left a comment
Contributor
There was a problem hiding this comment.
I tested this branch in my computer and at lnls449. The test consisted in compiling the code and calculate the twiss parameters for the SIRIUS model. It worked on both computers.
VitorSouzaLNLS
approved these changes
Jul 28, 2026
VitorSouzaLNLS
left a comment
Contributor
There was a problem hiding this comment.
I also tested it on my PC (Debian 12 @ WSL - Windows 11), and it worked correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the help of AI chatbot, I modified trackcpp compilation/installation to build it in MacOS.
Branch tested on:
I would appreciate if you could test the branch on the LNLS computers as well. Thanks!
[AI-generated summary] Fix macOS build (Apple Clang + conda toolchain)
trackcpp didn't build on macOS. This fixes it without changing behavior on Linux/GCC.
include/trackcpp/auxiliary.h,src/trackcpp.cpp— guard the customisfiniteshim to real GCC only.#if __GNUC__ < 6was meant to declare a fallbackisfinitefor old GCC that lacksstd::isfinite. Apple Clang also defines__GNUC__(for compatibility) at a value< 6, so this shim got compiled on macOS too, colliding with the standard library's ownisfinite/std::isfinite. Changed todefined(__GNUC__) && !defined(__clang__) && __GNUC__ < 6in both the declaration and the definition. No effect on real GCC builds.Makefile— two independent fixes:$(CXX) -MM ...(auto-dependency generation) ran without$(INC), so on macOS it can't resolve include paths (e.g. GSL from a non-default prefix) and fails/produces a broken.depend. Added$(INC)to the invocation.LDFLAGS += -Wl,-rpath,$(CONDA_PREFIX)/libwhen$(CONDA_PREFIX)is set, so the binary can find libraries (e.g. GSL) installed in the active conda env at runtime — macOS doesn't fall back to the same default library search paths Linux does. No-op when not in a conda env.python_package/Makefile— three fixes, all macOS-specific via a newUNAME_S := $(shell uname -s)branch (Linux path is untouched):.soon macOS needs-bundle -undefined dynamic_lookup, not-shared(ld64 doesn't support-sharedthe way GNU ld does for Python modules); added aSOFLAGSvariable, Darwin vs. else.-Wl,--whole-archive ... --no-whole-archive(used to force-link all oflibtrackcpp.ainto the extension) isn't supported by macOS's linker; the equivalent is-Wl,-force_load,$(TRACKCPPLIB). Added anARCHIVE_LINKvariable, same branch.-MMdependency generation had the same missing-$(INC)problem as the top-level Makefile (can't find Python/numpy/GSL headers); fixed the same way.numpy.iwas fetched with a hardcodedwgetcall;wgetisn't installed by default on macOS. Falls back tocurl -sLwhenwgetisn't onPATH.src/output.cpp—fprintf(fp, "...%s...", rad_dict[accelerator.radiation_on])passed astd::stringdirectly through a varargs%s, which is undefined behavior (relies on the string's internal ABI layout rather than aconst char*). It happened to work under libstdc++/GCC but breaks under libc++/Clang. Fixed all 4 call sites (print_closed_orbit,print_tracking_linepass,print_tracking_ringpass,print_dynapgrid) to use.c_str(). This is a real correctness fix, not macOS-only — worth taking regardless of platform.