gpac / gpac

GPAC Ultramedia OSS for Video Streaming & Next-Gen Multimedia Transcoding, Packaging & Delivery
https://gpac.io
GNU Lesser General Public License v2.1
2.77k stars 532 forks source link

build fail in master brach on mac #2640

Closed fastfading closed 1 year ago

fastfading commented 1 year ago

mac m1 chips follow https://github.com/gpac/gpac/wiki/GPAC-Build-Guide-for-OSX#mp4box-only to build

commit 7edc40feef23efd8c9948292d269eae76fa475af (HEAD -> master, origin/master, origin/HEAD) Author: jeanlf jeanlf@gpac.io Date: Thu Oct 12 16:58:53 2023 +0200

Fixed #2625

ld: warning: ignoring duplicate libraries: '-lbz2', '-lcaca', '-lfreetype', '-lnghttp2', '-lpng16', '-lpthread', '-lz' ld: Undefined symbols: _memrchr, referenced from: _gf_props_parse_value in libgpac_static.a234 clang: error: linker command failed with exit code 1 (use -v to see invocation)

---chatgpt answer---

If you are trying to build on Mac, the function memrchr is not available in the macOS libc. This function is a GNU extension and is not present on all systems, including macOS.

You will need to either conditionally use an alternative function when building on Mac, or provide your own implementation of memrchr.

Here's an example of a simple memrchr implementation:

void *memrchr(const void *s, int c, size_t n) {
    const unsigned char *cp;
    if (n != 0) {
        cp = (unsigned char *)s + n;
        do {
            if (*(--cp) == (unsigned char)c)
                return (void *)cp;
        } while (--n != 0);
    }
    return NULL;
}

You can include this function in your code when you're building on macOS. Be sure to wrap it with an #ifdef check to ensure it's only used when memrchr is not available:

#ifndef HAVE_MEMRCHR
void *memrchr(const void *s, int c, size_t n) {
    /* ... function code ... */
}
#endif

Then, in your build system, ensure that HAVE_MEMRCHR is defined when building on systems that have memrchr.

jeanlf commented 1 year ago

It looks like you have a local modification/forked version, there's no memrchr used in the code:

% grep -R memrchr gpac/src/*
% 
fastfading commented 1 year ago
./configure --static-bin

** System Configuration
Install prefix: /usr/local
Source path: /Users/huzhang2/git/mac/gpac
C   compiler: gcc
C++ compiler: g++
make: make
CPU: unknown
Big Endian: no

** GPAC 2.3-DEV rev597-g52cd40b83-master Core Configuration **
Static binaries enabled
debug version: no
GProf enabled: no
Memory tracking enabled: no
Sanitizer enabled: no
Fixed-Point Version: no
IPV6 Support: no
QuickJS Support: yes (with qjs-libc)

** Detected libraries **
zlib: system (pkgconfig)
OpenGL support: no
OpenSSL support: no
nghttp2: system (pkgconfig)
OSS Audio: no
ALSA Audio: no
Jack Audio: no
Pulse Audio: no
DirectFB: no
X11: no
SDL: no
FreeType: system (pkgconfig)
JPEG: no
OpenJPEG: no
PNG: system (pkgconfig)
MAD: no
FAAD: no
XVID: no
libcaption: no
MpeghDecoder: no
libcaca: system (pkgconfig)
FFMPEG: no
LZMA: no
Xiph Vorbis: no
Xiph Theora: no
A52 (AC3): no
OpenSVCDecoder: no
OpenHEVCDecoder: no
Platinum UPnP: no
Freenect: no

Creating config.mak
config.h is unchanged
Check config.log for detection failures

Warning: static binaries on OSX cannot remove all dependendencies to system libraries

Done - type 'make help' for make info, 'make' to build
ld: warning: ignoring duplicate libraries: '-lbz2', '-lcaca', '-lfreetype', '-lnghttp2', '-lpng16', '-lpthread', '-lz'
ld: Undefined symbols:
  _memrchr, referenced from:
      _gf_props_parse_value in libgpac_static.a[234](filter_props.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
❯ nm filter_props.o | grep memrchr
                 U _memrchr
❯ git pull
Already up to date.
❯ git remote -v
origin  https://github.com/gpac/gpac.git (fetch)
origin  https://github.com/gpac/gpac.git (push)
❯ git reset --hard master
HEAD is now at 52cd40b83 reframer_mhas: add size check (ref #2635 part 4)

I am sure I am on branch master

JuanMorenoS commented 1 year ago

Same issue

JuanMorenoS commented 1 year ago

I tested building GPAC on the previous version of MacOS, and it worked. Apparently, Apple changed something in the new version of Clang, and it's not working in Sonoma

JuanMorenoS commented 11 months ago

Works if optimization is deactivated as mentioned in: #2673

aureliendavid commented 11 months ago

Works if optimization is deactivated as mentioned in: #2673

thanks for feedback

if you can update to latest master it should work with optimizations enabled too