MacOS reports compilation errors during build time

Build Environment:

Node version : v16.13.1
npm version : 8.3.0
make: GNU Make 3.81
gcc and g++ version 7.5.0
clang version: Apple clang version 13.0.0 (clang-1300.0.29.3)
python: 3.9.7
xcode version : 13.0

OS:
macOS : 11.6
CPU: Intel Core i5

Install mediasoup-demo

  • mediasoup version: 3.9.3

Installation environment requirements

node >= v12.0.0
python >= 3.6
GNU make
gcc and g++ >= 4.9

Meet the requirements

bug description

Build steps:

> git clone https://github.com/versatica/mediasoup-demo.git
> cd mediasoup-demo
> git checkout v3
> cd server
> npm install # wait 
> The error message is at the bottom

try

  1. Use the command
    PYTHON=python3.9 npm install mediasoup@3 --save
    error - The error message is at the bottom
  2. delet node_modules file ,And then trying npm install
    error - The error message is at the bottom

No solution found online

....

4275 error [945/991] Compiling C++ object mediasoup-worker.p/src_RTC_UdpSocket.cpp.o
4275 error [946/991] Compiling C++ object mediasoup-worker.p/src_RTC_Codecs_H264.cpp.o
4275 error [947/991] Compiling C++ object mediasoup-worker.p/src_RTC_Codecs_VP8.cpp.o
4275 error [948/991] Compiling C++ object mediasoup-worker.p/src_RTC_Codecs_VP9.cpp.o
4275 error [949/991] Compiling C++ object mediasoup-worker.p/src_RTC_Transport.cpp.o
4275 error [950/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_Media.cpp.o
4275 error [951/991] Compiling C++ object mediasoup-worker.p/src_RTC_WebRtcTransport.cpp.o
4275 error [952/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_Parameters.cpp.o
4275 error [953/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtcpFeedback.cpp.o
4275 error [954/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtcpParameters.cpp.o
4275 error [955/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpCodecMimeType.cpp.o
4275 error [956/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpHeaderExtensionParameters.cpp.o
4275 error [957/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpCodecParameters.cpp.o
4275 error [958/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpHeaderExtensionUri.cpp.o
4275 error [959/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpRtxParameters.cpp.o
4275 error [960/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpEncodingParameters.cpp.o
4275 error [961/991] Compiling C++ object mediasoup-worker.p/src_RTC_SctpDictionaries_SctpStreamParameters.cpp.o
4275 error [962/991] Compiling C++ object mediasoup-worker.p/src_RTC_RtpDictionaries_RtpParameters.cpp.o
4275 error [963/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_Packet.cpp.o
4275 error [964/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_CompoundPacket.cpp.o
4275 error [965/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_SenderReport.cpp.o
4275 error [966/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_ReceiverReport.cpp.o
4275 error [967/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_Bye.cpp.o
4275 error [968/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_Sdes.cpp.o
4275 error [969/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_Feedback.cpp.o
4275 error [970/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpNack.cpp.o
4275 error [971/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPs.cpp.o
4275 error [972/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtp.cpp.o
4275 error [973/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpTmmb.cpp.o
4275 error [974/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpSrReq.cpp.o
4275 error [975/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpTllei.cpp.o
4275 error [976/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpEcn.cpp.o
4275 error [977/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsPli.cpp.o
4275 error [978/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsSli.cpp.o
4275 error [979/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsRpsi.cpp.o
4275 error [980/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpTransport.cpp.o
4275 error [981/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsFir.cpp.o
4275 error [982/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsTst.cpp.o
4275 error [983/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsVbcm.cpp.o
4275 error [984/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsLei.cpp.o
4275 error [985/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsAfb.cpp.o
4275 error [986/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_FeedbackPsRemb.cpp.o
4275 error [987/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_XR.cpp.o
4275 error [988/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_XrDelaySinceLastRr.cpp.o
4275 error [989/991] Compiling C++ object mediasoup-worker.p/src_RTC_RTCP_XrReceiverReferenceTime.cpp.o
4275 error [990/991] Compiling C++ object mediasoup-worker.p/src_main.cpp.o
4275 error [991/991] Linking target mediasoup-worker
4275 error FAILED: mediasoup-worker 
4275 error c++  -o mediasoup-worker mediasoup-worker.p/src_lib.cpp.o mediasoup-worker.p/src_DepLibSRTP.cpp.o mediasoup-worker.p/src_DepLibUV.cpp.o mediasoup-worker.p/src_DepLibWebRTC.cpp.o mediasoup-worker.p/src_DepOpenSSL.cpp.o mediasoup-worker.p/src_DepUsrSCTP.cpp.o mediasoup-worker.p/src_Logger.cpp.o mediasoup-worker.p/src_MediaSoupErrors.cpp.o mediasoup-worker.p/src_Settings.cpp.o mediasoup-worker.p/src_Worker.cpp.o mediasoup-worker.p/src_Utils_Crypto.cpp.o mediasoup-worker.p/src_Utils_File.cpp.o mediasoup-worker.p/src_Utils_IP.cpp.o mediasoup-worker.p/src_Utils_String.cpp.o mediasoup-worker.p/src_handles_SignalsHandler.cpp.o mediasoup-worker.p/src_handles_TcpConnectionHandler.cpp.o mediasoup-worker.p/src_handles_TcpServerHandler.cpp.o mediasoup-worker.p/src_handles_Timer.cpp.o mediasoup-worker.p/src_handles_UdpSocketHandler.cpp.o mediasoup-worker.p/src_handles_UnixStreamSocket.cpp.o 

….

mediasoup-worker.p/src_RTC_RTCP_Bye.cpp.o mediasoup-worker.p/src_RTC_RTCP_Feedback.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPs.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtp.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpNack.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpTmmb.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpSrReq.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpTllei.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpEcn.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackRtpTransport.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsPli.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsSli.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsRpsi.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsFir.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsTst.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsVbcm.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsLei.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsAfb.cpp.o mediasoup-worker.p/src_RTC_RTCP_FeedbackPsRemb.cpp.o mediasoup-worker.p/src_RTC_RTCP_XR.cpp.o mediasoup-worker.p/src_RTC_RTCP_XrDelaySinceLastRr.cpp.o mediasoup-worker.p/src_RTC_RTCP_XrReceiverReferenceTime.cpp.o mediasoup-worker.p/src_main.cpp.o -L/usr/local/opt/binutils/lib -I/usr/local/opt/binutils/include -Wl,-dead_strip_dylibs -Wl,-headerpad_max_install_names -Wl,-undefined,error subprojects/openssl-1.1.1l/libcrypto.a subprojects/openssl-1.1.1l/libssl.a subprojects/libuv-v1.42.0/libuv.a subprojects/libsrtp-2.4.2/libsrtp2.a subprojects/usrsctp-9d6b99b10a70f7a63d21cd80d03c353da9ac19d3/libusrsctp.a deps/libwebrtc/liblibwebrtc.a subprojects/abseil-cpp-20210324.2/libabsl_strings.a subprojects/abseil-cpp-20210324.2/libabsl_base.a subprojects/abseil-cpp-20210324.2/libabsl_numeric.a subprojects/abseil-cpp-20210324.2/libabsl_types.a
4275 error ld: warning: ignoring file subprojects/libuv-v1.42.0/libuv.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
4275 error ld: warning: ignoring file subprojects/openssl-1.1.1l/libcrypto.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64
4275 error ld: warning: ignoring file subprojects/libsrtp-2.4.2/libsrtp2.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file subprojects/abseil-cpp-20210324.2/libabsl_strings.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file subprojects/abseil-cpp-20210324.2/libabsl_base.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file subprojects/abseil-cpp-20210324.2/libabsl_numeric.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file subprojects/usrsctp-9d6b99b10a70f7a63d21cd80d03c353da9ac19d3/libusrsctp.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file subprojects/abseil-cpp-20210324.2/libabsl_types.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file subprojects/openssl-1.1.1l/libssl.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error ld: warning: ignoring file deps/libwebrtc/liblibwebrtc.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
4275 error Undefined symbols for architecture x86_64:
4275 error   "_ASN1_INTEGER_set", referenced from:
4275 error       RTC::DtlsTransport::GenerateCertificateAndPrivateKey() in src_RTC_DtlsTransport.cpp.o
4275 error   "_BIO_ctrl", referenced from:
4275 error       RTC::DtlsTransport::~DtlsTransport() in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::Run(RTC::DtlsTransport::Role) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::ProcessDtlsData(unsigned char const*, unsigned long) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::SendApplicationData(unsigned char const*, unsigned long) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::OnTimer(Timer*) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::CheckRemoteFingerprint() in src_RTC_DtlsTransport.cpp.o
4275 error   "_BIO_free", referenced from:
4275 error       RTC::DtlsTransport::DtlsTransport(RTC::DtlsTransport::Listener*) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::CheckRemoteFingerprint() in src_RTC_DtlsTransport.cpp.o
4275 error   "_BIO_new", referenced from:
4275 error       RTC::DtlsTransport::DtlsTransport(RTC::DtlsTransport::Listener*) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::CheckRemoteFingerprint() in src_RTC_DtlsTransport.cpp.o
4275 error   "_BIO_s_mem", referenced from:
4275 error       RTC::DtlsTransport::DtlsTransport(RTC::DtlsTransport::Listener*) in src_RTC_DtlsTransport.cpp.o
4275 error       RTC::DtlsTransport::CheckRemoteFingerprint() in src_RTC_DtlsTransport.cpp.o
4275 error   "_BIO_write", referenced from:
4275 error       RTC::DtlsTransport::ProcessDtlsData(unsigned char const*, unsigned long) in src_RTC_DtlsTransport.cpp.o
4275 error   "_DTLS_method", referenced from:
4275 error       RTC::DtlsTransport::CreateSslCtx() in src_RTC_DtlsTransport.cpp.o
4275 error   "_DTLS_set_timer_cb", referenced from:
4275 error       RTC::DtlsTransport::DtlsTransport(RTC::DtlsTransport::Listener*) in src_RTC_DtlsTransport.cpp.o
4275 error   "_EC_KEY_free", referenced from:
4275 error       RTC::DtlsTransport::GenerateCertificateAndPrivateKey() in src_RTC_DtlsTransport.cpp.o
4275 error   "_EC_KEY_generate_key", referenced from:
4275 error       RTC::DtlsTransport::GenerateCertificateAndPrivateKey() in src_RTC_DtlsTransport.cpp.o
4275 error   "_EC_KEY_new_by_curve_name", referenced from:
4275 error       RTC::DtlsTransport::GenerateCertificateAndPrivateKey() in src_RTC_DtlsTransport.cpp.o
…… 
4275 error   "_uv_write", referenced from:
4275 error       TcpConnectionHandler::Write(unsigned char const*, unsigned long, std::__1::function<void (bool)> const*) in src_handles_TcpConnectionHandler.cpp.o
4275 error       TcpConnectionHandler::Write(unsigned char const*, unsigned long, unsigned char const*, unsigned long, std::__1::function<void (bool)> const*) in src_handles_TcpConnectionHandler.cpp.o
4275 error       UnixStreamSocket::Write(unsigned char const*, unsigned long) in src_handles_UnixStreamSocket.cpp.o
4275 error ld: symbol(s) not found for architecture x86_64
4275 error clang: error: linker command failed with exit code 1 (use -v to see invocation)
4275 error ninja: build stopped: subcommand failed.
4276 error npm WARN using --force Recommended protections disabled.
4276 error
4276 error Usage:   
4276 error   /usr/local/opt/python@3.9/bin/python3.9 -m pip install [options] <requirement specifier> [package-index-options] ...
4276 error   /usr/local/opt/python@3.9/bin/python3.9 -m pip install [options] -r <requirements file> [package-index-options] ...
4276 error   /usr/local/opt/python@3.9/bin/python3.9 -m pip install [options] [-e] <vcs project url> ...
4276 error   /usr/local/opt/python@3.9/bin/python3.9 -m pip install [options] [-e] <local project path> ...
4276 error   /usr/local/opt/python@3.9/bin/python3.9 -m pip install [options] <archive url/path> ...
4276 error
4276 error no such option: --system
4276 error Directory does not contain a valid build tree:
4276 error /Users/sky/.npm/_cacache/tmp/git-cloneSLNeUy/worker/out/Release/build

....
                                                                                                    
make: *** [mediasoup-worker] Error 1
4276 error npm ERR! code 1
4276 error npm ERR! path /Users/sky/.npm/_cacache/tmp/git-cloneSLNeUy
4276 error npm ERR! command failed
4276 error npm ERR! command sh -c node npm-scripts.js postinstall
4276 error
4276 error npm ERR! A complete log of this run can be found in:
4276 error npm ERR!     /Users/sky/.npm/_logs/2021-12-31T06_54_30_205Z-debug-0.log
4277 verbose exit 1
4278 timing npm Completed in 581177ms
4279 verbose unfinished npm timer reify 1640933490317
4280 verbose unfinished npm timer reify:unpack 1640933664109
4281 verbose unfinished npm timer reifyNode:node_modules/mediasoup 1640933664191
4282 verbose code 1
4283 error A complete log of this run can be found in:
4283 error     /Users/sky/.npm/_logs/2021-12-31T06_51_29_658Z-debug-0.log

I think the error seems to be caused by the failure of the ninja compilation in mediasoup-worker.

There must be something wrong with the compiler in your case. We run both GCC and Clang in CI and it works in both cases, I honestly can’t know what else might be wrong there.

You can try to use CC and CXX environment variables to specify alternative compiler, but I have no idea which compiler you’re using as the beginning of the log is truncated (typically it is Apple’s Clang by default though).

Your suggestion works for me.
I can see from your comment

  • The problem is with my compiler
  • Your use of gcc and clang is effective, indicating that I have a problem with the configuration of gcc and clang

Solution:

I changed a mac computer and reconfigured the environment, and it did compile successfully.

Explain that the problem lies in the compiler configuration
Personal feeling is caused by the environmental error of gcc and clang

End

Finally, thank you for your suggestion

Can you tell me how you configue your compiler