3

I am working on a project that implements OhNet Library. It also gives you the opportunity og using The project was started when I joined the team and they gave the compiled library and the implementation. After redoing some classes and Clearing all the warning, the last one I have is "libstdc++ is deprecated; move to libc++ [-Wdeprecated]". I hope that by changing to the suggested choice the warning would go away BUT I get a bunch off compiling errors

Undefined symbols for architecture arm64:
  "std::_List_node_base::unhook()", referenced from:
      OpenHome::Net::CpiSubscriptionManager::Run() in libohNetCore.a(CpiSubscription.o)
      OpenHome::Net::DviSubscriptionManager::Run() in libohNetCore.a(DviSubscription.o)
      OpenHome::Net::CpiDeviceListUpdater::~CpiDeviceListUpdater() in libohNetCore.a(CpiDevice.o)
      OpenHome::Net::CpiDeviceListUpdater::Run() in libohNetCore.a(CpiDevice.o)
      OpenHome::NetworkAdapterChangeNotifier::~NetworkAdapterChangeNotifier() in libohNetCore.a(NetworkAdapterList.o)
      OpenHome::NetworkAdapterChangeNotifier::Run() in libohNetCore.a(NetworkAdapterList.o)
      OpenHome::Net::XmlFetchManager::~XmlFetchManager() in libohNetCore.a(XmlFetcher.o)
      ...
  "std::__throw_length_error(char const*)", referenced from:
      std::vector<OpenHome::Net::Argument*, std::allocator<OpenHome::Net::Argument*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::Net::Argument**, std::vector<OpenHome::Net::Argument*, std::allocator<OpenHome::Net::Argument*> > >, OpenHome::Net::Argument* const&) in libohNetCore.a(CpiService.o)
      std::vector<OpenHome::Net::DvAction, std::allocator<OpenHome::Net::DvAction> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::Net::DvAction*, std::vector<OpenHome::Net::DvAction, std::allocator<OpenHome::Net::DvAction> > >, OpenHome::Net::DvAction const&) in libohNetCore.a(DviService.o)
      std::vector<OpenHome::Net::Property*, std::allocator<OpenHome::Net::Property*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::Net::Property**, std::vector<OpenHome::Net::Property*, std::allocator<OpenHome::Net::Property*> > >, OpenHome::Net::Property* const&) in libohNetCore.a(DviService.o)
      std::vector<OpenHome::Net::DviSubscription*, std::allocator<OpenHome::Net::DviSubscription*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::Net::DviSubscription**, std::vector<OpenHome::Net::DviSubscription*, std::allocator<OpenHome::Net::DviSubscription*> > >, OpenHome::Net::DviSubscription* const&) in libohNetCore.a(DviService.o)
      std::vector<OpenHome::Net::Parameter*, std::allocator<OpenHome::Net::Parameter*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::Net::Parameter**, std::vector<OpenHome::Net::Parameter*, std::allocator<OpenHome::Net::Parameter*> > >, OpenHome::Net::Parameter* const&) in libohNetCore.a(Service.o)
      std::vector<OpenHome::MListener*, std::allocator<OpenHome::MListener*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::MListener**, std::vector<OpenHome::MListener*, std::allocator<OpenHome::MListener*> > >, OpenHome::MListener* const&) in libohNetCore.a(Env.o)
      std::vector<OpenHome::ISuspendObserver*, std::allocator<OpenHome::ISuspendObserver*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<OpenHome::ISuspendObserver**, std::vector<OpenHome::ISuspendObserver*, std::allocator<OpenHome::ISuspendObserver*> > >, OpenHome::ISuspendObserver* const&) in libohNetCore.a(Env.o)

I am using "libohNetCore.a" and "libohNetProxies.a"

Why am I getting this errors? What is exactly this change doing?

Thank you very much.

Community
  • 1
  • 1
Reimond Hill
  • 4,278
  • 40
  • 52
  • 2
    How could C++ libraries be a C language problem? Please don't use unrelated tags. – Gerhardh Oct 25 '17 at 08:03
  • It looks like your code and the libohNetCore library have been compiled with different versions of the C++ standard library. If you want to remove the warning, you should probably recompile the libohNetCore library with the same settings you want to use. – Niall Oct 25 '17 at 08:11
  • Sorry but I missed some tags. The library has it's own binding c/c++ files. – Reimond Hill Oct 25 '17 at 08:28

1 Answers1

2

You can't use the already compiled .a files when you change to a different implementation of the C++ standard libraries.

These libraries appear to have been compiled with libstdc++, and as such expose methods that will only work with libstdc++. You would need copies of libohNetCore.a and libohNetProxies.a that were compiled with libc++ in order to have them work when you switch to libc++.

I downloaded the OhNet code from github. It's defined to support -miphoneos-version-min=2.2 so it will compile with libstdc++, as it will be built to support iOS 2.2 and newer.

If you change the minimum targeted iOS to 5.0, then you can add -stdlib=libc++ to the compile line:

compiler = $(toolroot)/clang -stdlib=libc++

and it will compile with libc++.

If you change the minimum targeted iOS to 7.0 then it will compile with libc++ by default, and once you've compiled you will have the libOhNetCore.a compiled for libc++.

To check if a .a is compiled for libstdc++ or libc++, you need to run an nm on it looking for, for example, std::string e.g.

$ nm ./Build/Obj/iOS-arm64/Release/libohNetCore.a | c++filt | grep std::string | head -1
0000000000000084 T OpenHome::Net::CpDeviceCpp::GetAttribute(char const*, std::string&) const

This is compiled with libstdc++ - the presence of std::string indicates this.

for libc++, the pattern is slightly different:

$ nm ./Build/Obj/iOS-arm64/Release/libohNetCore.a | c++filt | grep string | head -1
0000000000000084 T OpenHome::Net::CpDeviceCpp::GetAttribute(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const

i.e. the presence of std::__1 indicates that it's compiled with libc++.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • Thank you very much for your answer. That is what i thought. Is there any change ("Quick fix") to recompile .a files with libc++ without having the original precompiled library? – Reimond Hill Oct 25 '17 at 08:26
  • What consequences will it have into an iOS project? – Reimond Hill Oct 25 '17 at 08:31
  • You can't quick-fix the `.a` files - you'll need the full source to get them built so that they would work with `libc++`. It sounds likely that you should be able to get those open home .a files compiled with `libc++` (based on some reading around). You can still use c++ code compiled with `libstdc++` on iOS, the issue is that it's an older library with less support for C++11 features, and has not been updated in a while, so some code *might* not compile. – Anya Shenanigans Oct 25 '17 at 14:06
  • I've added some details to the answer as to how to build with `libc++` instead of `libstdc++`. On OSX it compiles with `libc++` by default, so the code should be clean for use with those standard libraries – Anya Shenanigans Oct 25 '17 at 14:35
  • Oh thank you very much! You are an start! I was looking at the think you pointed out but a little bit confused about it. I am going to try ant surely give a positive! – Reimond Hill Oct 26 '17 at 09:02
  • Hi, What you said it definitely worked. but i am getting an error: **make: /Developer/MonoTouch/usr/bin/smcs: No such file or directory make: *** [Build/Obj/iOS-arm64/Debug/ohNet.net.dll] Error 1** when i Executed **make iOs-arm64=1 platform=iOS debug=1** – Reimond Hill Oct 26 '17 at 13:03
  • You need `mono` installed to compile the `.dll` files; however by the point that error happens, you should already have the relevant `.a` files. If you use the `find . -name \*.a` it will find the compiled `.a` files in the build tree. – Anya Shenanigans Oct 26 '17 at 13:21
  • thank you very much. I really found your explanation really Helpful. It was really difficult to find any! – Reimond Hill Nov 07 '17 at 09:51
  • Do you know how to import it to Xcode? Are the .dll needed for the .a? – Reimond Hill Sep 07 '18 at 07:53
  • The .dll files are needed for `C#` bindings, which is *not* for iOS. For importing the library, you need to add the path to the `.a` to the `Library Search Paths` build settings, and the path to the `.h` files to the `Header Search Paths`. This is a short comment/answer - there are [other questions](https://stackoverflow.com/questions/39648816/linking-a-static-c-library-in-xcode-7) already here asking the same thing. – Anya Shenanigans Sep 07 '18 at 08:14
  • Thank you petesh. it has been a while but I had some issues with the project. I am going to post an answer with added info but yours will be the accepted. – Reimond Hill Sep 07 '18 at 10:05