--- a/configure +++ b/configure @@ -1289,12 +1289,27 @@ log test_ld "$@" type=$1 shift 1 + linker=$ld + linkerflags=$LDFLAGS + use_cxx_linker=false + test "$type" = cxx && use_cxx_linker=true + for opt; do + test "$opt" = "$cxx_linker_flag" && use_cxx_linker=true + done flags=$(filter_out '-l*|*.so' $@) libs=$(filter '-l*|*.so' $@) + flags=$(filter_out "$cxx_linker_flag" $flags) + libs=$(filter_out "$cxx_linker_flag" $libs) test_$type $($cflags_filter $flags) || return flags=$($ldflags_filter $flags) libs=$($ldflags_filter $libs) - test_cmd $ld $LDFLAGS $LDEXEFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs + if $use_cxx_linker; then + linker=$cxx + linkerflags="$CXXFLAGS $LDFLAGS" + test_cmd $linker $linkerflags $LDEXEFLAGS $flags $(cxx_o $TMPE) $TMPO $libs $extralibs + else + test_cmd $linker $linkerflags $LDEXEFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs + fi } check_ld(){ @@ -1647,11 +1662,11 @@ pkg_cflags=$($pkg_config --cflags $pkg_config_flags $pkg) pkg_libs=$($pkg_config --libs $pkg_config_flags $pkg) pkg_incdir=$($pkg_config --variable=includedir $pkg_config_flags $pkg) - check_class_headers_cxx "$headers" "$classes" $pkg_cflags $pkg_libs "-lstdc++" "$@" && + check_class_headers_cxx "$headers" "$classes" $pkg_cflags $pkg_libs "$cxx_linker_flag" "$@" && enable $name && set_sanitized "${name}_cflags" $pkg_cflags && set_sanitized "${name}_incdir" $pkg_incdir && - set_sanitized "${name}_extralibs" $pkg_libs "-lstdc++" + set_sanitized "${name}_extralibs" $pkg_libs "$cxx_linker_flag" } check_pkg_config(){ @@ -3531,7 +3546,7 @@ ddagrab_filter_deps="d3d11va IDXGIOutput1 DXGI_OUTDUPL_FRAME_INFO" gfxcapture_filter_deps="cxx17 threads d3d11va IGraphicsCaptureItemInterop __x_ABI_CWindows_CGraphics_CCapture_CIGraphicsCaptureSession3" -gfxcapture_filter_extralibs="-lstdc++" +gfxcapture_filter_extralibs="$cxx_linker_flag" scale_d3d11_filter_deps="d3d11va" scale_d3d12_filter_deps="d3d12va ID3D12VideoProcessor" deinterlace_d3d12_filter_deps="d3d12va ID3D12VideoProcessor" @@ -3971,11 +3986,11 @@ caca_outdev_deps="libcaca" decklink_deps_any="libdl LoadLibrary" decklink_indev_deps="decklink threads" -decklink_indev_extralibs="-lstdc++" +decklink_indev_extralibs="$cxx_linker_flag" decklink_indev_suggest="libzvbi" decklink_outdev_deps="decklink threads" decklink_outdev_suggest="libklvanc" -decklink_outdev_extralibs="-lstdc++" +decklink_outdev_extralibs="$cxx_linker_flag" dshow_indev_deps="IBaseFilter" dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi" fbdev_indev_deps="linux_fb_h" @@ -4464,6 +4479,9 @@ host_extralibs='-lm' host_cflags_filter=echo host_ldflags_filter=echo +# Internal marker for configure tests and generated makefiles to use CXX +# as the linker driver without hardcoding a specific C++ runtime library. +cxx_linker_flag='--ffmpeg-cxx-linker' target_path='$(CURDIR)' @@ -7269,13 +7287,13 @@ require_headers "glslang/build_info.h" && { test_cpp_condition glslang/build_info.h "GLSLANG_VERSION_MAJOR >= 16" && spvremap="" ; } check_lib spirv_library glslang/Include/glslang_c_interface.h glslang_initialize_process \ -lglslang -lMachineIndependent -lGenericCodeGen \ - ${spvremap} -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lstdc++ $libm_extralibs $pthreads_extralibs || + ${spvremap} -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools $cxx_linker_flag $libm_extralibs $pthreads_extralibs || require spirv_library glslang/Include/glslang_c_interface.h glslang_initialize_process \ -lglslang -lMachineIndependent -lOSDependent -lHLSL -lOGLCompiler -lGenericCodeGen \ - ${spvremap} -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lstdc++ $libm_extralibs $pthreads_extralibs ; + ${spvremap} -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools $cxx_linker_flag $libm_extralibs $pthreads_extralibs ; fi enabled libgme && { check_pkg_config libgme libgme gme/gme.h gme_new_emu || - require libgme gme/gme.h gme_new_emu -lgme -lstdc++; } + require libgme gme/gme.h gme_new_emu -lgme $cxx_linker_flag; } enabled libgsm && { for gsm_hdr in "gsm.h" "gsm/gsm.h"; do check_lib libgsm "${gsm_hdr}" gsm_create -lgsm && break; done || die "ERROR: libgsm not found"; } @@ -7343,7 +7361,7 @@ enabled libopenh264 && require_pkg_config libopenh264 "openh264 >= 1.3.0" wels/codec_api.h WelsGetCodecVersion enabled libopenjpeg && { check_pkg_config libopenjpeg "libopenjp2 >= 2.1.0" openjpeg.h opj_version || { require_pkg_config libopenjpeg "libopenjp2 >= 2.1.0" openjpeg.h opj_version -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } } -enabled libopenmpt && require_pkg_config libopenmpt "libopenmpt >= 0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create -lstdc++ && append libopenmpt_extralibs "-lstdc++" +enabled libopenmpt && require_pkg_config libopenmpt "libopenmpt >= 0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create $cxx_linker_flag && append libopenmpt_extralibs "$cxx_linker_flag" enabled libopenvino && { { check_pkg_config libopenvino openvino openvino/c/openvino.h ov_core_create && enable openvino2; } || { check_pkg_config libopenvino openvino c_api/ie_c_api.h ie_c_api_version || require libopenvino c_api/ie_c_api.h ie_c_api_version -linference_engine_c_api; } } @@ -7364,12 +7382,12 @@ enabled librist && require_pkg_config librist "librist >= 0.2.7" librist/librist.h rist_receiver_create enabled librsvg && require_pkg_config librsvg librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_new_from_data enabled librtmp && require_pkg_config librtmp librtmp librtmp/rtmp.h RTMP_Socket -enabled librubberband && require_pkg_config librubberband "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new -lstdc++ && append librubberband_extralibs "-lstdc++" +enabled librubberband && require_pkg_config librubberband "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new $cxx_linker_flag && append librubberband_extralibs "$cxx_linker_flag" enabled libshaderc && require_pkg_config spirv_library "shaderc >= 2019.1" shaderc/shaderc.h shaderc_compiler_initialize enabled libshine && require_pkg_config libshine shine shine/layer3.h shine_encode_buffer enabled libsmbclient && { check_pkg_config libsmbclient smbclient libsmbclient.h smbc_init || require libsmbclient libsmbclient.h smbc_init -lsmbclient; } -enabled libsnappy && require libsnappy snappy-c.h snappy_compress -lsnappy -lstdc++ +enabled libsnappy && require libsnappy snappy-c.h snappy_compress -lsnappy $cxx_linker_flag enabled libsoxr && require libsoxr soxr.h soxr_create -lsoxr enabled libssh && require_pkg_config libssh "libssh >= 0.6.0" libssh/sftp.h sftp_init enabled libspeex && require_pkg_config libspeex speex speex/speex.h speex_decoder_init @@ -7381,7 +7399,7 @@ enabled libtheora && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg enabled libtls && require_pkg_config libtls libtls tls.h tls_configure && { enabled gpl && ! enabled nonfree && die "ERROR: LibreSSL is incompatible with the gpl"; } -enabled libtorch && check_cxxflags -std=c++17 && require_cxx libtorch torch/torch.h "torch::Tensor" -ltorch -lc10 -ltorch_cpu -lstdc++ -lpthread +enabled libtorch && check_cxxflags -std=c++17 && require_cxx libtorch torch/torch.h "torch::Tensor" -ltorch -lc10 -ltorch_cpu $cxx_linker_flag -lpthread enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame && { check_lib libtwolame twolame.h twolame_encode_buffer_float32_interleaved -ltwolame || die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; } @@ -8588,6 +8606,7 @@ CC_O=$CC_O CXX_C=$CXX_C CXX_O=$CXX_O +CXXLINKERFLAG=$cxx_linker_flag GLSLC_O=$GLSLC_O NVCC_C=$NVCC_C NVCC_O=$NVCC_O --- a/ffbuild/common.mak +++ b/ffbuild/common.mak @@ -17,7 +17,9 @@ ifeq ($(LD),$(CC)) ifneq ($(CXX),) LDXX := $(CXX) -LINK = $(if $(filter -lstdc++,$(1)),$(LDXX) $(filter-out -lstdc++,$(1)),$(LD) $(1)) +# Link C++-dependent targets with the C++ driver so it can select the +# appropriate runtime library for the active toolchain. +LINK = $(if $(filter $(CXXLINKERFLAG),$(1)),$(LDXX) $(filter-out $(CXXLINKERFLAG),$(1)),$(LD) $(1)) endif endif