Bug 57117 - When building towrads physical device, getting error: "Native linking failed, undefined symbol..." When building towards simulator, getting error: 'can't lipo directories'.
Summary: When building towrads physical device, getting error: "Native linking failed,...
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: XI 10.10 (d15-2)
Hardware: All Windows
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-06-02 19:57 UTC by Ammar Mheir
Modified: 2017-09-11 15:13 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Full Build Output Logs (521.57 KB, text/plain)
2017-06-02 19:57 UTC, Ammar Mheir
Details

Description Ammar Mheir 2017-06-02 19:57:06 UTC
Created attachment 22663 [details]
Full Build Output Logs

##Overview 

When building Xamarin.iOS project references a Native Framework within a binding project, will get various errors when building towards a physical device:

Native linking failed, undefined symbol: _PrepareClassifier. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.

Additionally, attempting to build for iPhoneSimulator, will receive error:

Internal error: 'can't lipo directories'. Please file a bug report with a test case (http://bugzilla.xamarin.com).

This happens regardless of what the Linker Setting has been set to and adding various mtouch arguments such as 
-cxx -gcc_flags "-lc++"
Will result in fewer errors however nevertheless still get the same issue. The following is the sample replicating this issue: https://www.dropbox.com/s/hpwonexnfcf8d1z/TestCase.zip?dl=0


##Observed outcome

When building in iPhone configuration, will receive build errors stating that the Native linking has failed due to undefined symbols. The following is a small snippet from the full build logs which is attached to this report:

>  clang: error: linker command failed with exit code 1 (use -v to see invocation) (TaskId:93)
>   (TaskId:93)
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: _PrepareClassifier. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: _PrepareClassifier_FromMultiDataBase. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: _RecognizeOneImage. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: std::terminate(). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: operator delete[](void*). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: operator delete(void*). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: operator new[](unsigned long). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: operator new(unsigned long). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: ___cxa_begin_catch. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: ___gxx_personality_v0. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed, undefined symbol: _wb_lloio. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(747,3): error : Native linking failed. Please review the build log.
>  Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution finished. (TaskId:93)
>  MTouch: 2017-06-02T14:04:29.3609712-05:00 - Finished (TaskId:93)
>Done executing task "MTouch" -- FAILED. (TaskId:93)
>Done building target "_CompileToNative" in project "Xamarin.CamScanner.Test.csproj" -- FAILED.: (TargetId:150)

The above error is also observed when building on the Mac using Visual Studio for Mac.


##Expected Results

Xamarin.iOS project will build and deploy successfully when referencing binding project which is in turn referencing the Native Frameworks. 


##Workarounds attempted

-Attempted changing the Linker settings to each one of the linker options resulting in the same behavior
-Added mtouch arguments -cxx -gcc_flags "-lc++"
-Adding mtouch argument --registrar:dynamic will result in an error 'can't lipo directories', I'm assuming this is because that registrar value defaults to simulator builds. 
-Set the native frameworks within the Binding project to enable Smart Link and enable Force Load, and disabling them both.
-Attempted selecting only single architectures to build against, yielding same results.


##Version Information

#Visual Studio

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Xamarin.iOS   10.10.0.35 (4cffddf)


#Visual Studio for Mac

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.0.1 (build 24)
Installation UUID: 1621b137-c1b7-473d-9609-23de9d4cac12
Runtime:
	Mono 5.0.1.1 (2017-02/5077205) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500010001

=== .NET Core ===

Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Sdks

=== Apple Developer Tools ===

Xcode 8.3.2 (12175)
Build 8E2002

=== Xamarin.iOS ===

Version: 10.10.0.36 (Visual Studio Enterprise)
Hash: d2270eec
Branch: d15-2
Build date: 2017-05-22 16:30:53-0400

=== Build Information ===

Release ID: 700010024
Git revision: 7ab1ca2ced6f584e56b7a0d4d321d00775cd95c9
Build date: 2017-05-19 05:44:51-04
Xamarin addins: 08d17158f3365beee5e60f67999e607cce4b3f93
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.3
Darwin 16.4.0 Darwin Kernel Version 16.4.0
    Thu Dec 22 22:53:21 PST 2016
    root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64


##Additional Information

User experiencing this error:
https://forums.xamarin.com/discussion/94345/native-framework-binding
Comment 1 Manuel de la Peña 2017-06-05 09:22:35 UTC
Can you provide a sample project to reproduce the issue? Would need to decide if it is an issue in VS or the Xamarin.iOS platform.
Comment 2 Ammar Mheir 2017-06-05 09:25:12 UTC
Thanks for looking into this, I have already provided the link in my first comment to the test case. Please let me know if there is any troubles downloading it: https://www.dropbox.com/s/hpwonexnfcf8d1z/TestCase.zip?dl=0
Comment 3 Ammar Mheir 2017-06-06 14:51:51 UTC
Changing back to new as we were able to provide a sample.
Comment 4 Manuel de la Peña 2017-06-07 09:50:16 UTC
Hello,

Got the sample and there are three diff projects, can you please let me know how the three projects are related? Are they meant to be in the same solution, how do they depend from each other. Once I got this info I'll continue investigating. Thx!
Comment 5 Ammar Mheir 2017-06-07 17:52:39 UTC
Included in test case folder is the CamScanner.Test folder, which is an Objective C project that makes use of the API (.framework). The ImageProcessingBinding folder is a Xamarin Binding Library that binds the API, and the Xamarin.CamScanner.Test folder is the Xamarin project that references the Binding Library.

If we reference the native .frameworks into the Binding project, and then refernce the Binding project into the Xamarin.iOS project. we would get the above mentioned error. However the Binding project is building successfully. If I directly reference the native .frameworks into the Xamarin.iOS project rather than the binding project, I oddly enough get the same issue. 

They are separated it seems for troubleshooting purposes (it's how the project was sent to me) however I see no difference whether I add the Binding project into the Solution that contains the Xamarin.iOS project. The Xamarin.CamScanner.Test project currently references the binding project but is not included in the same solution. I added it into the same solution but made no difference. 

There was some more info on this in the following link: https://forums.xamarin.com/discussion/94345/native-framework-binding
Comment 6 Rolf Bjarne Kvinge [MSFT] 2017-06-15 10:18:58 UTC
The "can't lipo directories" problem has been reported elsewhere and is already fixed: bug #56635.
Comment 7 Manuel de la Peña 2017-07-06 08:48:23 UTC
Setting as duplicate as per @rolf info.

*** This bug has been marked as a duplicate of bug 56635 ***
Comment 8 Rolf Bjarne Kvinge [MSFT] 2017-07-06 08:56:16 UTC
Only the simulator problem ("can't lipo directories") is a duplicate, the problem on a device isn't (at least not obviously so by just looking at the error message).
Comment 9 Manuel de la Peña 2017-07-17 09:25:01 UTC
Confirmed both with master and xcode9.

Note You need to log in before you can comment on or make changes to this bug.