macOS Ventura 13.6.2
Gerbil v0.18-62-gf7d8efcf on Gambit v4.9.5-78-g8b18ab69
λ echo $CC
gcc-13
Running brew info ncurses
gives us the following part:
If you need to have ncurses first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/ncurses/bin:$PATH"' >> ~/.zshrc
For compilers to find ncurses you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/ncurses/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ncurses/include"
For pkg-config to find ncurses you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/ncurses/lib/pkgconfig"
Right now, I can't use pkg-config ncurses
with --libs
or with --cflags
.
Let's set PKG_CONFIG_PATH
to fix that.
export PKG_CONFIG_PATH="/opt/homebrew/opt/ncurses/lib/pkgconfig"
After that both of them work:
λ pkg-config ncurses --libs
-L/opt/homebrew/Cellar/ncurses/6.4/lib -Wl,-search_paths_first -lncursesw
λ pkg-config ncurses --cflags
-D_DARWIN_C_SOURCE -DNCURSES_WIDECHAR -I/opt/homebrew/Cellar/ncurses/6.4/include/ncursesw -I/opt/homebrew/Cellar/ncurses/6.4/include
:std/make
provides helper functions for setting both ldflags
and cppflags
. If I've read the source code correctly these should both first try to use pkg-config
to get --libs
and --cflags
respectively. If pkg-config
fails they fallback to the second argument of the function.
Combined with the info from brew info ncurses
before I landed in the
following:
#!/usr/bin/env gxi
;;; -*- Gerbil -*-
(import :std/build-script
:std/make)
; Can we do this outside of the `defbuild-script`?
; Where else would I put this?
(setenv "PKG_CONFIG_PATH" "/opt/homebrew/opt/ncurses/lib/pkgconfig")
; `build.ss` expects a `main` function
; `defbuild-script` is a helper to create that
(defbuild-script
`("rogue/lib" "rogue/ncurses"
(exe: "rogue/main" bin: "rogue"
; I looked in some other code to see how these functions are used
; https://github.com/mighty-gerbils/gerbil/blob/f7d8efcf4a25014b4b969eb6e21a3006d256f22e/src/std/build-spec.ss#L201
; if `PKG_CONFIG_PATH` is set correctly here then these should succeed?
"-cc-options" ,(cppflags "ncurses" "")
"-ld-options" ,(ldflags "ncurses" "-lncurses"))))
I tried finding more info about constructing your own make
function but my
Gerbil-foo is too low to understand what the defbuild-script
does I am afraid
:(
Perhaps the most important question: the Gerbil file in question looks like this, is this correct?!
;;; -*- Gerbil -*-
(import :std/foreign)
(export #t)
(begin-ffi (initscr)
(c-declare "#include <ncurses.h>")
(define-c-lambda initscr () void "initscr"))
Running gxpkg build
λ gxpkg build
... build in current directory
... compile rogue/ncurses
ld: Undefined symbols:
_initscr, referenced from:
____H_ncurses____0 in ncurses__0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"gcc"
*** Unhandled exception in #<thread #45>
*** ERROR IN ?
--- Syntax Error at compile: Compilation error; process exit with nonzero status
... form: Continuation backtrace:
[0] gxc#gsc-compile-file
[1] gxc#compile-scm-file__%
[2] gxc#compile-runtime-code
[3] gxc#compile-runtime-code
*** ERROR IN std/misc/concurrent-plan#perform-plan/threads__% -- Build Failure at rogue/ncurses
*** ERROR IN ?
--- Syntax Error at compile: Compilation error; process exit with nonzero status
... form: "gcc"
*** ERROR IN std/misc/process#run-process__% --
*** ERROR IN "misc/process.ss"@28.35-28.46 [ProcessError]: process exited with non-zero status
--- irritants: "/Users/p1xelher0/code/github/p1xelHer0/rogue-gerbil/build.ss" 17920 (path: "/Users/p1xelher0/code/github/p1xelHer0/rogue-gerbil/build.ss" arguments: ("compile") environment: #f directory: #f stdin-redirection: #t stdout-redirection: #f stderr-redirection: #f pseudo-terminal: #f show-console: #f)
--- continuation backtrace:
[0] raise
[1] std/misc/process#run-process__% ((if (let () (declare (not safe)) (procedure? _check-status568387_)) _check-s...
It's worth noting that I can compile the following C program.
#include <ncurses.h>
int main(int argc, char **argv)
{
initscr();
WINDOW *win = newwin(5, 10, 0, 0);
refresh();
box(win, 0, 0);
mvwprintw(win, 2, 2, "Hello");
wrefresh(win);
getch();
endwin();
return 0;
}
Compiling with gcc-13
:
λ gcc-13 test.c -o test.out -lncurses -v
Using built-in specs.
COLLECT_GCC=gcc-13
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/lto-wrapper
Target: aarch64-apple-darwin22
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin22 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Homebrew GCC 13.2.0)
COLLECT_GCC_OPTIONS='-o' 'test.out' '-v' '-mmacosx-version-min=13.0.0' '-asm_macosx_version_min=13.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'test.out-'
/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/cc1 -quiet -v -iprefix /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/ -D__DYNAMIC__ test.c -fPIC -quiet -dumpdir test.out- -dumpbase test.c -dumpbase-ext .c -mmacosx-version-min=13.0.0 -mlittle-endian -mabi=lp64 -version -o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccodHRh5.s
GNU C17 (Homebrew GCC 13.2.0) version 13.2.0 (aarch64-apple-darwin22)
compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version 4.2.0-p12, MPC version 1.3.1, isl version isl-0.26-GMP
warning: GMP header version 6.2.1 differs from library version 6.3.0.
warning: MPFR header version 4.2.0-p12 differs from library version 4.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../../../../../aarch64-apple-darwin22/include"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/local/include"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include-fixed"
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../../../../../aarch64-apple-darwin22/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include
/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks
End of search list.
Compiler executable checksum: 1ed03ec2fbe7f047297ce1fbd4c59f18
COLLECT_GCC_OPTIONS='-o' 'test.out' '-v' '-mmacosx-version-min=13.0.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'test.out-'
as -arch arm64 -v -mmacosx-version-min=13.0 -o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccACXEB9.o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccodHRh5.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1as -triple arm64-apple-macosx13.0.0 -filetype obj -main-file-name ccodHRh5.s -target-cpu apple-m1 -target-feature +v8.5a -target-feature +crc -target-feature +lse -target-feature +rdm -target-feature +crypto -target-feature +dotprod -target-feature +fp-armv8 -target-feature +neon -target-feature +fp16fml -target-feature +ras -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -fdebug-compilation-dir=/Users/p1xelher0/code/github/p1xelHer0/rogue-gerbil -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccACXEB9.o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccodHRh5.s
COMPILER_PATH=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/
LIBRARY_PATH=/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../../
COLLECT_GCC_OPTIONS='-o' 'test.out' '-v' '-mmacosx-version-min=13.0.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'test.out.'
/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/collect2 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/ -dynamic -arch arm64 -platform_version macos 13.0.0 0.0 -o test.out -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13 -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../.. /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccACXEB9.o -lncurses -lemutls_w -lgcc -lSystem -lgcc -no_compact_unwind -rpath @loader_path -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc/aarch64-apple-darwin22/13 -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current
ld: warning: ignoring duplicate libraries: '-lgcc'
g
Compiling with flags from pkg-config
λ gcc-13 test.c -o test.out `pkg-config ncurses --libs --cflags` -v
Using built-in specs.
COLLECT_GCC=gcc-13
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/lto-wrapper
Target: aarch64-apple-darwin22
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin22 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Homebrew GCC 13.2.0)
COLLECT_GCC_OPTIONS='-o' 'test.out' '-D' '_DARWIN_C_SOURCE' '-D' 'NCURSES_WIDECHAR' '-I' '/opt/homebrew/Cellar/ncurses/6.4/include/ncursesw' '-I' '/opt/homebrew/Cellar/ncurses/6.4/include' '-L/opt/homebrew/Cellar/ncurses/6.4/lib' '-v' '-mmacosx-version-min=13.0.0' '-asm_macosx_version_min=13.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'test.out-'
/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/cc1 -quiet -v -I /opt/homebrew/Cellar/ncurses/6.4/include/ncursesw -I /opt/homebrew/Cellar/ncurses/6.4/include -iprefix /opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/ -D__DYNAMIC__ -D _DARWIN_C_SOURCE -D NCURSES_WIDECHAR test.c -fPIC -quiet -dumpdir test.out- -dumpbase test.c -dumpbase-ext .c -mmacosx-version-min=13.0.0 -mlittle-endian -mabi=lp64 -version -o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//cchnwnwa.s
GNU C17 (Homebrew GCC 13.2.0) version 13.2.0 (aarch64-apple-darwin22)
compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version 4.2.0-p12, MPC version 1.3.1, isl version isl-0.26-GMP
warning: GMP header version 6.2.1 differs from library version 6.3.0.
warning: MPFR header version 4.2.0-p12 differs from library version 4.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../../../../../aarch64-apple-darwin22/include"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/local/include"
ignoring duplicate directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include-fixed"
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../../../../../aarch64-apple-darwin22/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/Cellar/ncurses/6.4/include/ncursesw
/opt/homebrew/Cellar/ncurses/6.4/include
/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include
/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks
End of search list.
Compiler executable checksum: 1ed03ec2fbe7f047297ce1fbd4c59f18
COLLECT_GCC_OPTIONS='-o' 'test.out' '-D' '_DARWIN_C_SOURCE' '-D' 'NCURSES_WIDECHAR' '-I' '/opt/homebrew/Cellar/ncurses/6.4/include/ncursesw' '-I' '/opt/homebrew/Cellar/ncurses/6.4/include' '-L/opt/homebrew/Cellar/ncurses/6.4/lib' '-v' '-mmacosx-version-min=13.0.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'test.out-'
as -arch arm64 -v -I /opt/homebrew/Cellar/ncurses/6.4/include/ncursesw -I /opt/homebrew/Cellar/ncurses/6.4/include -mmacosx-version-min=13.0 -o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccwqyq07.o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//cchnwnwa.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1as -triple arm64-apple-macosx13.0.0 -filetype obj -main-file-name cchnwnwa.s -target-cpu apple-m1 -target-feature +v8.5a -target-feature +crc -target-feature +lse -target-feature +rdm -target-feature +crypto -target-feature +dotprod -target-feature +fp-armv8 -target-feature +neon -target-feature +fp16fml -target-feature +ras -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -I /opt/homebrew/Cellar/ncurses/6.4/include/ncursesw -I /opt/homebrew/Cellar/ncurses/6.4/include -fdebug-compilation-dir=/Users/p1xelher0/code/github/p1xelHer0/rogue-gerbil -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -I /opt/homebrew/Cellar/ncurses/6.4/include/ncursesw -I /opt/homebrew/Cellar/ncurses/6.4/include -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccwqyq07.o /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//cchnwnwa.s
COMPILER_PATH=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/
LIBRARY_PATH=/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../../
COLLECT_GCC_OPTIONS='-o' 'test.out' '-D' '_DARWIN_C_SOURCE' '-D' 'NCURSES_WIDECHAR' '-I' '/opt/homebrew/Cellar/ncurses/6.4/include/ncursesw' '-I' '/opt/homebrew/Cellar/ncurses/6.4/include' '-L/opt/homebrew/Cellar/ncurses/6.4/lib' '-v' '-mmacosx-version-min=13.0.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'test.out.'
/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/13/collect2 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/ -dynamic -arch arm64 -platform_version macos 13.0.0 0.0 -o test.out -L/opt/homebrew/Cellar/ncurses/6.4/lib -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13 -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc -L/opt/homebrew/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/aarch64-apple-darwin22/13/../../.. /var/folders/3z/4rtvbvk578g2byfj_r0r2flw0000gn/T//ccwqyq07.o -search_paths_first -lncursesw -lemutls_w -lgcc -lSystem -lgcc -no_compact_unwind -rpath @loader_path -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc/aarch64-apple-darwin22/13 -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current/gcc -rpath /opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/current
ld: warning: ignoring duplicate libraries: '-lgcc'
- Some things: I don't get the
rpath
thing nor what evenstripping
. Perhapsrpath
is the missing part? pkg-config
now works on my machine to find the installedncurses
- I don't know about "building a Homebrew package"