flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.74k stars 27.37k forks source link

engine linker error `framework not found for -framework Flutter` #105632

Open gaaclarke opened 2 years ago

gaaclarke commented 2 years ago

description

Sometimes after having pulled a new version of the engine then running gclient sync, the engine won't build because of a linker error framework not found for -framework Flutter. The workaround is to delete the build folders and run gn again. I noticed it about a month ago the first time.

environment

engine hash: 10ff30257d7671fa4f96189607487dd62c550f36 platform: macOS

error

[10/2537] SOLINK libcopy_and_verify_framework_module.dylib libcopy_and_verify_framework_module.dylib.TOC
FAILED: libcopy_and_verify_framework_module.dylib libcopy_and_verify_framework_module.dylib.TOC 
if [ ! -e ./libcopy_and_verify_framework_module.dylib -o ! -e ./libcopy_and_verify_framework_module.dylib.TOC ] || otool -l ./libcopy_and_verify_framework_module.dylib | grep -q LC_REEXPORT_DYLIB ; then ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Users/aaclarke/dev/engine/src/out/ios_profile/gen/SDKs/iPhoneOS15.4.sdk -miphoneos-version-min=11.0  -Wl,-object_path_lto,./lto_libcopy_and_verify_framework_module.o -arch arm64 -stdlib=libc++ -Wl,-dead_strip -o ./libcopy_and_verify_framework_module.dylib -Wl,-filelist,./libcopy_and_verify_framework_module.dylib.rsp    && { otool -l ./libcopy_and_verify_framework_module.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libcopy_and_verify_framework_module.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libcopy_and_verify_framework_module.dylib.TOC; else ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Users/aaclarke/dev/engine/src/out/ios_profile/gen/SDKs/iPhoneOS15.4.sdk -miphoneos-version-min=11.0  -Wl,-object_path_lto,./lto_libcopy_and_verify_framework_module.o -arch arm64 -stdlib=libc++ -Wl,-dead_strip -o ./libcopy_and_verify_framework_module.dylib -Wl,-filelist,./libcopy_and_verify_framework_module.dylib.rsp    && { otool -l ./libcopy_and_verify_framework_module.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libcopy_and_verify_framework_module.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libcopy_and_verify_framework_module.dylib.tmp && if ! cmp -s ./libcopy_and_verify_framework_module.dylib.tmp ./libcopy_and_verify_framework_module.dylib.TOC; then mv ./libcopy_and_verify_framework_module.dylib.tmp ./libcopy_and_verify_framework_module.dylib.TOC ; fi; fi
ld64.lld: error: framework not found for -framework Flutter
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
chinmaygarde commented 2 years ago

We should probably have a local-engine-development tag for such quality of life issues when developing the engine locally.

endless7 commented 2 years ago

It still happen in the lastest engine version.

cyanglaz commented 2 years ago

This also happens for iOS builds. (In case the original issue is about targeting macos)

zhongwuzw commented 2 years ago

Happened when build iOS debug engine frequently. And if I change the default linker from lld to ld, the error disappears.

[1/178] SOLINK libcopy_and_verify_framework_module.dylib libcopy_and_verify_framework_module.dylib.TOC
FAILED: libcopy_and_verify_framework_module.dylib libcopy_and_verify_framework_module.dylib.TOC
if [ ! -e ./libcopy_and_verify_framework_module.dylib -o ! -e ./libcopy_and_verify_framework_module.dylib.TOC ] || otool -l ./libcopy_and_verify_framework_module.dylib | grep -q LC_REEXPORT_DYLIB ; then ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -miphoneos-version-min=11.0  -Wl,-object_path_lto,./lto_libcopy_and_verify_framework_module.o -arch arm64 -stdlib=libc++ -o ./libcopy_and_verify_framework_module.dylib -Wl,-filelist,./libcopy_and_verify_framework_module.dylib.rsp    && { otool -l ./libcopy_and_verify_framework_module.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libcopy_and_verify_framework_module.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libcopy_and_verify_framework_module.dylib.TOC; else ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -miphoneos-version-min=11.0  -Wl,-object_path_lto,./lto_libcopy_and_verify_framework_module.o -arch arm64 -stdlib=libc++ -o ./libcopy_and_verify_framework_module.dylib -Wl,-filelist,./libcopy_and_verify_framework_module.dylib.rsp    && { otool -l ./libcopy_and_verify_framework_module.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libcopy_and_verify_framework_module.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libcopy_and_verify_framework_module.dylib.tmp && if ! cmp -s ./libcopy_and_verify_framework_module.dylib.tmp ./libcopy_and_verify_framework_module.dylib.TOC; then mv ./libcopy_and_verify_framework_module.dylib.tmp ./libcopy_and_verify_framework_module.dylib.TOC ; fi; fi
ld64.lld: error: framework not found for -framework Flutter
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
[4/178] ACTION //flutter/lib/snapshot:generate_snapshot_bin(//build/toolchain/mac:ios_clang_arm)
ninja: build stopped: subcommand failed.
begabug commented 2 years ago

Happened when build iOS debug engine frequently. And if I change the default linker from lld to ld, the error disappears.

[1/178] SOLINK libcopy_and_verify_framework_module.dylib libcopy_and_verify_framework_module.dylib.TOC
FAILED: libcopy_and_verify_framework_module.dylib libcopy_and_verify_framework_module.dylib.TOC
if [ ! -e ./libcopy_and_verify_framework_module.dylib -o ! -e ./libcopy_and_verify_framework_module.dylib.TOC ] || otool -l ./libcopy_and_verify_framework_module.dylib | grep -q LC_REEXPORT_DYLIB ; then ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -miphoneos-version-min=11.0  -Wl,-object_path_lto,./lto_libcopy_and_verify_framework_module.o -arch arm64 -stdlib=libc++ -o ./libcopy_and_verify_framework_module.dylib -Wl,-filelist,./libcopy_and_verify_framework_module.dylib.rsp    && { otool -l ./libcopy_and_verify_framework_module.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libcopy_and_verify_framework_module.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libcopy_and_verify_framework_module.dylib.TOC; else ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -miphoneos-version-min=11.0  -Wl,-object_path_lto,./lto_libcopy_and_verify_framework_module.o -arch arm64 -stdlib=libc++ -o ./libcopy_and_verify_framework_module.dylib -Wl,-filelist,./libcopy_and_verify_framework_module.dylib.rsp    && { otool -l ./libcopy_and_verify_framework_module.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libcopy_and_verify_framework_module.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libcopy_and_verify_framework_module.dylib.tmp && if ! cmp -s ./libcopy_and_verify_framework_module.dylib.tmp ./libcopy_and_verify_framework_module.dylib.TOC; then mv ./libcopy_and_verify_framework_module.dylib.tmp ./libcopy_and_verify_framework_module.dylib.TOC ; fi; fi
ld64.lld: error: framework not found for -framework Flutter
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
[4/178] ACTION //flutter/lib/snapshot:generate_snapshot_bin(//build/toolchain/mac:ios_clang_arm)
ninja: build stopped: subcommand failed.

And how can I set default linker from lld to ld?

zhongwuzw commented 2 years ago

You can change gn compiler config https://github.com/flutter/buildroot/blob/c5de0c1ef5ff5f4fd8f6ce99674accb534643d75/build/config/compiler/BUILD.gn#L194, add something like ldflags += [ "-fuse-ld=ld" ]

begabug commented 2 years ago

You can change gn compiler config https://github.com/flutter/buildroot/blob/c5de0c1ef5ff5f4fd8f6ce99674accb534643d75/build/config/compiler/BUILD.gn#L194, add something like ldflags += [ "-fuse-ld=ld" ]

Thanks a ton!