2

I have created a shared object for Android in Visual Studio 2015.

It works fine so far, but pop_back() for a wstring does not work:

        wstring element = "JustATest!";
        if (element.back() == L'!')
        {
            element.pop_back();
        }

VS2015 tells me: "no member named 'pop_back' in 'std::basic_string<wchar_t>'".

Can anybody tell me how to get rid of this error? I have no idea why this should not work. Is that because for some reason VS2015 does not use C++11 here?

Thank you for the help!

Edit: Another error:

When I try to use _wtoi, VS tells me: "use of undeclared identifier '_wtoi'. Very very strange.

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • According to MSDN it does: https://msdn.microsoft.com/en-us/library/ee404847(v=vs.140).aspx – Steve May 28 '15 at 13:01
  • @Steve Yes, I thought so, too. But appearantly it does not work yet. – tmighty May 28 '15 at 21:49
  • I just tried it in VS2013 and it worked fine. I simply copied and pasted your code above into `main()`. I did, however, have to make one small change to get it to compile, put and "L" in front of the string constant: `wstring element = L"JustATest!";` I assume you have `#include `? – Steve May 28 '15 at 21:55
  • I have read that cross-platform requires VS2015. Usually I use VS2013. Could you tell me what you have done to be able to create a cross-platform application on VS2013? – tmighty May 28 '15 at 21:58
  • Ah ... no I was building a native Windows command line application. That might be the problem, if there is something specific that's different between the two targets. I can't help you there. – Steve May 28 '15 at 21:59
  • :-) Thank you anyway! :-) – tmighty May 28 '15 at 22:04
  • I thought 2015 used clang for x-platform? If so, what clang version? – Yakk - Adam Nevraumont May 28 '15 at 22:42
  • I am not sure about the add-ons. I just noticed that VS2015 told something about NDK. I have not seen anything about clang. – tmighty May 28 '15 at 22:46
  • Yes, I have now found out that VS uses clang.exe, but I don't see which version it is. The clang.exe that I found on my disc does not have a version number. – tmighty May 30 '15 at 18:25

1 Answers1

1

You need to turn on STL support. Turn on STL with Configuration Properties -> General -> Use of STL. Good options are LLVM libc++ static library (fewer features, more compatible with CLANG) and GNU STL static library (more features, I had an issue that required me to turn the CLANG optimizer to -Oz to prevent a segfault).

Matthew Grivich
  • 431
  • 3
  • 12
  • Thanks, I never noticed this option. When I change the library, I do see that some wstring options work and some others do not. Same goes for _wtoi and _wtof. However there is no library that would enable me to use wstring.pop_back and _wtoi at the same time. Do you know why this is so? Is it still bleeding edge and might be fixed in the next month or do I have to work around it because it will not get fixed? – tmighty Jun 03 '15 at 14:14
  • 1
    _wtoi is platform dependent, where the platform is windows, not android/linux. I don't expect _wtoi to be ported to anything compatible with android. There are various dead end options out there, but the best one (i.e. it works) I found is to use boost::lexical_cast<>. [link](http://stackoverflow.com/questions/5118308/how-to-convert-stdwstring-to-numeric-typeint-long-float) Of course, this means that you need to include the relevant boost header files in your project. – Matthew Grivich Jun 03 '15 at 17:37
  • Isn't it crazy that I have include a special library just to convert a wstring into an int value? There is no other way, is there? – tmighty Jun 03 '15 at 18:53
  • 1
    I don't know of an easier way to replace _wtoi, but there may be a method that I'm not aware of. Yes, it is crazy. Just so you know, Android NDK coding is full of gotchas like this. Stack overflow isn't the place for rants, so I'll leave it at that. – Matthew Grivich Jun 03 '15 at 22:44
  • Can you confirm that you are able to compile a shared object on VS2015 with LLVM libc++ static library? I am using clang 3.4, and I am targetting Android-19. I am getting all kinds of errors indicating that something goes horribly wrong. It is really difficult to find out the error when so many build tools are involved (VS, Clang, NDK, etc.). Thanks. – tmighty Jun 03 '15 at 23:55
  • ps: I mean using Boost. Without Boost, it compiles fine for me. – tmighty Jun 04 '15 at 00:27
  • You don't need to compile a shared library. The relevant library is header only. Under Project Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories, add $(SolutionDir)..\..\external\boost\boost_1_55_0 (or wherever you store the headers). Then `#include "boost/lexical_cast.hpp"` in your source file. It works for me. – Matthew Grivich Jun 04 '15 at 16:50
  • Could you try compiling unsigned int wstringtounsignedint(wstring u) { return boost::lexical_cast(u); } against ARM? It does not work for me. I am getting a clang.exe compiler error telling me about an undefined reference to boost::throw_exception – tmighty Jun 06 '15 at 22:40
  • Hmmmm, I just could not get it to work. I am now using wstringstream convert(). I hope that this will not result in a pitfall sometime. – tmighty Jun 06 '15 at 23:13