fluent/fluent-bit

build: can't compile `onigmo` on macOS: `Undefined symbols for architecture x86_64`

Dentrax opened this issue · 15 comments

Bug Report

Describe the bug
Can't compile fluent-bit on macOS.

To Reproduce

    1. $ cd build/
    1. cmake ../
    1. make
$ make

[  1%] Built target backtrace
Consolidate compiler generated dependencies of target c-ares
[  7%] Built target c-ares
Consolidate compiler generated dependencies of target jsmn
[  7%] Built target jsmn
Consolidate compiler generated dependencies of target sqlite3
[  7%] Built target sqlite3
Consolidate compiler generated dependencies of target xxd-c
[  7%] Built target xxd-c
[  8%] Performing build step for 'onigmo'
Making all in .
Making all in sample
libtool: link: gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -o encode encode.o  ../.libs/libonigmo.a
ld: warning: ignoring file ../.libs/libonigmo.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture x86_64:
  "_OnigDefaultSyntax", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
  "_OnigEncodingASCII", referenced from:
      _main in encode.o
  "_OnigEncodingBIG5", referenced from:
      _main in encode.o
  "_OnigEncodingEUC_CN", referenced from:
      _main in encode.o
  "_OnigEncodingEUC_KR", referenced from:
      _main in encode.o
  "_OnigEncodingEUC_TW", referenced from:
      _main in encode.o
  "_OnigEncodingGB18030", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_1", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_10", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_11", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_13", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_14", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_15", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_16", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_2", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_3", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_4", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_5", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_6", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_7", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_8", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_9", referenced from:
      _main in encode.o
  "_OnigEncodingKOI8_R", referenced from:
      _main in encode.o
  "_OnigEncodingKOI8_U", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_16BE", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_16LE", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_32BE", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_32LE", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1250", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1251", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1252", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1253", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1254", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1257", referenced from:
      _main in encode.o
  "_onig_end", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
  "_onig_error_code_to_str", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
      _search in encode.o
  "_onig_free", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
  "_onig_get_encoding", referenced from:
      _search in encode.o
  "_onig_new", referenced from:
      _exec in encode.o
  "_onig_new_deluxe", referenced from:
      _exec_deluxe in encode.o
  "_onig_region_free", referenced from:
      _search in encode.o
  "_onig_region_new", referenced from:
      _search in encode.o
  "_onig_search", referenced from:
      _search in encode.o
  "_onigenc_str_bytelen_null", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [encode] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all] Error 2
make[2]: *** [onigmo-prefix/src/onigmo-stamp/onigmo-build] Error 2
make[1]: *** [CMakeFiles/onigmo.dir/all] Error 2
make: *** [all] Error 2

and $ make -j 16 throws different error: (this is different issue i guess)

$ make -j 16

make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: *** [CMakeFiles/onigmo.dir/all] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/backtrace.dir/all] Error 1
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: *** [tools/xxd-c/CMakeFiles/xxd-c.dir/all] Error 1
make[1]: *** [lib/c-ares-809d5e84/src/lib/CMakeFiles/c-ares.dir/all] Error 1
make[1]: *** [lib/sqlite-amalgamation-3330000/CMakeFiles/sqlite3.dir/all] Error 1
[  0%] Built target jsmn
make: *** [all] Error 2

Expected behavior
It should compile?

Screenshots

Your Environment

  • Version used: cmake version 3.22.3 and GNU Make 3.81
  • Configuration: default
  • Environment name and version (e.g. Kubernetes? What version?): macOS 12.1
  • Server type and version:
  • Operating System and version: Darwin 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64 and xcode-select version 2392
  • Filters and plugins: -

Additional context
-

What I'm missing here?

Have you followed the instructions here? https://docs.fluentbit.io/manual/installation/macos#get-the-source-and-build-it

We do not have any CI for MacOS yet so that's probably something to add @niedbalski but there are people building for MacOS so may just need a docs update or similar?

I've tried exact same instructions and filed two following PRs for docs:

We do not have any CI for MacOS yet

Adding macOS in the build matrix would be great. Are there any tracking issue for that?

I'm not sure, we have some general CI improvements ones.
Likely it wants a PR to go into the reusable workflow we have or added to the unstable + staging builds like the Windows CI.

Which branch are you trying to build? Have you deleted all files inside the build dir before building? I saw this in the past but for M1. In the error message that you see, both architectures are the same (macOS-x86_64).

master branch with clean build dir. (fresh clone)

I think we can remove waiting-for-user label.

Hi @Dentrax
We've recently merged a couple of fixes for MacOS builds. Can you please try HEAD from master and let us know?
Thanks!

Thanks, just tried on the commit: 7a9ee96 (Fresh clone) but seems still no luck

$ cd build
$ cmake ../
$ make

Making all in sample
libtool: link: gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -o encode encode.o  ../.libs/libonigmo.a
ld: warning: ignoring file ../.libs/libonigmo.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture x86_64:
  "_OnigDefaultSyntax", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
...
...
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [encode] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all] Error 2
make[2]: *** [onigmo-prefix/src/onigmo-stamp/onigmo-build] Error 2
make[1]: *** [CMakeFiles/onigmo.dir/all] Error 2
make: *** [all] Error 2
$ make -j 16

make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: *** [CMakeFiles/onigmo.dir/all] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/backtrace.dir/all] Error 1
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: *** [lib/c-ares-809d5e84/src/lib/CMakeFiles/c-ares.dir/all] Error 1
make[1]: *** [lib/jsmn/CMakeFiles/jsmn.dir/all] Error 1
[  0%] Building C object lib/sqlite-amalgamation-3330000/CMakeFiles/sqlite3.dir/sqlite3.c.o
[  0%] Building C object tools/xxd-c/CMakeFiles/xxd-c.dir/xxd-c.c.o
[  0%] Linking C executable ../../bin/xxd-c
[  0%] Built target xxd-c
[  0%] Linking C static library ../../library/libsqlite3.a
[  0%] Built target sqlite3
make: *** [all] Error 2

Just give it a try on the latest commit 58aefb5 but still I couldn't able to compile it:

$ make

[  8%] Performing build step for 'onigmo'
Making all in .
Making all in sample
libtool: link: gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -o encode encode.o  ../.libs/libonigmo.a
ld: warning: ignoring file ../.libs/libonigmo.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture x86_64:
  "_OnigDefaultSyntax", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
  "_OnigEncodingASCII", referenced from:
      _main in encode.o
  "_OnigEncodingBIG5", referenced from:
      _main in encode.o
  "_OnigEncodingEUC_CN", referenced from:
      _main in encode.o
  "_OnigEncodingEUC_KR", referenced from:
      _main in encode.o
  "_OnigEncodingEUC_TW", referenced from:
      _main in encode.o
  "_OnigEncodingGB18030", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_1", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_10", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_11", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_13", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_14", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_15", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_16", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_2", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_3", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_4", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_5", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_6", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_7", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_8", referenced from:
      _main in encode.o
  "_OnigEncodingISO_8859_9", referenced from:
      _main in encode.o
  "_OnigEncodingKOI8_R", referenced from:
      _main in encode.o
  "_OnigEncodingKOI8_U", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_16BE", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_16LE", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_32BE", referenced from:
      _main in encode.o
  "_OnigEncodingUTF_32LE", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1250", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1251", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1252", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1253", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1254", referenced from:
      _main in encode.o
  "_OnigEncodingWindows_1257", referenced from:
      _main in encode.o
  "_onig_end", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
  "_onig_error_code_to_str", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
      _search in encode.o
  "_onig_free", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
  "_onig_get_encoding", referenced from:
      _search in encode.o
  "_onig_new", referenced from:
      _exec in encode.o
  "_onig_new_deluxe", referenced from:
      _exec_deluxe in encode.o
  "_onig_region_free", referenced from:
      _search in encode.o
  "_onig_region_new", referenced from:
      _search in encode.o
  "_onig_search", referenced from:
      _search in encode.o
  "_onigenc_str_bytelen_null", referenced from:
      _exec in encode.o
      _exec_deluxe in encode.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [encode] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all] Error 2
make[2]: *** [onigmo-prefix/src/onigmo-stamp/onigmo-build] Error 2
make[1]: *** [CMakeFiles/onigmo.dir/all] Error 2
make: *** [all] Error 2

If I run $ make -j 16 getting a completely different error:

make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: *** [tools/xxd-c/CMakeFiles/xxd-c.dir/all] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/backtrace.dir/all] Error 1
Consolidate compiler generated dependencies of target sqlite3
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: /Library/Developer/CommandLineTools/usr/bin/make: Permission denied
make[1]: *** [lib/sqlite-amalgamation-3330000/CMakeFiles/sqlite3.dir/all] Error 1
make[1]: *** [lib/c-ares-809d5e84/src/lib/CMakeFiles/c-ares.dir/all] Error 1
[  0%] Built target jsmn
make: *** [all] Error 2

Another issue is that if we pass -DCPACK_GENERATOR=productbuild to cmake as used in call-build-macos.yaml file, Makefile is not generated by cmake. Eventually, $ make --build . throws make: Makefile: No such file or directory error.

macOS build action is also different from official build document, which would slightly inconsistent.

cc @patrick-stephens

I'll try to write commands to reproduce this and keep things organized...

Environment: See the original issue

$ git clone git@github.com:fluent/fluent-bit.git
$ cd fluent-bit
$ brew update
$ brew install bison flex libyaml
$ export OPENSSL_ROOT_DIR=`brew --prefix openssl`
$ export PATH=`brew --prefix bison`/bin:$PATH
$ export LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib:$LIBRARY_PATH
$ cd build
# had to pass `-DFLB_CONFIG_YAML=Off` otherwise it fails
# had to remove `-DCPACK_GENERATOR=productbuild` otherwise Makefile is not generated
$ cmake -DFLB_DEV=on -DCMAKE_INSTALL_PREFIX=/opt/fluent-bit -DFLB_CONFIG_YAML=Off ../
$ cmake --build .
# See the error - second above post

Tried with gcc instead of clang:

$ brew install gcc@12
$ cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc-12 -DCMAKE_CXX_COMPILER=/usr/local/bin/g++-12 -DFLB_CONFIG_YAML=Off ../

Got exact same error.

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the exempt-stale label.

we moved to our maintained version of Onigmo in https://github.com/fluent/onigmo

we also added CMake support into onigmo, merged into Fluent Bit:

it should be ok now.

Thanks! 🚀

But unfortunately, I hit different issue related to LuaJIT: #5300 (comment) 🤔