Building on MacOS

For ages I've been trying to replaced my build system on a Debian VM for a native MacOS setup without success.

The Debian VM setup works perfectly, with dozens of successful builds but is very inconvenient an uncomfortable.

I use MacPorts and so, to satisfy requirements I've installed:

$ sudo port install coreutils asciidoc bzip2 fastjar flex getopt gtk2 intltool jikes zlib openssl p5-extutils-makemaker rsync ruby sdcc unzip gettext libxslt bison gawk autoconf wget gmake ncurses e2fsprogs ossp-uuid gawk findutils gnutar

And install a CaseSensitive disk image.

After git cloning and cd to the tree, I do:

$ ./scripts/feeds update -a

And I get:

...
Checking 'gcc'... ok.
Checking 'working-gcc'... ok.
Checking 'g++'... ok.
Checking 'working-g++'... failed.
...

Everything else is ok.

Looking into include/prereq-build.mk, I mimic:

$ echo 'int main(int argc, char **argv) { return 0; }' | g++ -x c++ -v -o ./a.out -

and I get:

...
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status

But I get the same with:

$ echo 'int main(int argc, char **argv) { return 0; }' | gcc -x c -v -o ./a.out -

which checks working-gcc ok.

EDIT (lack of -lstdc++):
$ echo 'int main(int argc, char **argv) { return 0; }' | gcc -x c -v -o ./a.out - -lstdc++

Achieves the same result; and so does:
$ echo 'int main(int argc, char **argv) { return 0; }' | gcc -x c -v -o ./a.out -lstdc++ -

My g++ is

$ g++ --verbose
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin19/9.4.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc9/gcc9/work/gcc-9.4.0/configure --prefix=/opt/local --build=x86_64-apple-darwin19 --enable-languages=c,c++,objc,obj-c++,lto,fortran,jit --libdir=/opt/local/lib/gcc9 --includedir=/opt/local/include/gcc9 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-9 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-9 --with-gxx-include-dir=/opt/local/include/gcc9/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-build-config=bootstrap-debug --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --enable-host-shared --disable-tls --with-pkgversion='MacPorts gcc9 9.4.0_0' --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
Thread model: posix
gcc version 9.4.0 (MacPorts gcc9 9.4.0_0)

Can somebody please help?
Thank you

I'm on 10.13 - I've compiled master about 2 weeks ago (as I recall there was a ninja build problem with some package so I reverted... something). That said, there were a few issues I faced with cmnake, ucert & libubox, but you aren't there yet.

So here are my steps (which I saved @ the rc3 release) & the only differences I see is the missing env.sh command & I'm using the Apple/Xcode llvm

hdiutil create -size 20g -type SPARSE -fs "Case-sensitive HFS+" -volname OpenWrt /Volumes/D2/pgm/Openwrt/OpenWrt.sparseimage

hdiutil attach /Volumes/D2/pgm/Openwrt/OpenWrt.sparseimage

sudo port install asciidoc coreutils findutils gawk grep getopt gnutar wget diffutils gmake ncurses pkgconfig patchutils p5-extutils-makemaker

cd /Volumes/OpenWrt

source /Volumes/OpenWrt/env.sh

git clone https://git.openwrt.org/openwrt/openwrt.git

cd /Volumes/OpenWrt/openwrt

git pull

git fetch --tags

git checkout v21.02.0-rc3

scripts/feeds update -a

scripts/feeds install -a

make download

make -j7 V=s

My env.sh isn't even everything from

just

PATH="/opt/local/libexec/gnubin:$PATH"
PATH="/opt/local/bin:$PATH"
export PATH
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

And my routers are running the resulting builds.

1 Like

You're absolutely right, thank you for sharing!

I just switched the /opt/local/bin/g++ symlink from the MacPort g++ to the Apple Xcode llvm and achieved success build. It must then be a bug on the configuration of g++.

I'm now turning to MacPorts forum to place the problem.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.