Compile C++ on phone
I'm starting to learn C++ and I'd like to test my cli app on a Nexus 5 running Ubuntu Touch.
At first I thought I could just compile a hello world script on my ARM laptop (PineBook Pro) and move the binary over but it does not work. So, now I've sshed into my nexus 5, enabled writable-image, and I'm basically just looking for the g++ binary so I can compile my program. For now it will be hello world but as I learn it will become more complex.
Anyone able to help me install/find GCC/G++ on the phone so I can compile it?
Un-tar a complete Linux and chroot into it.
Neat, I never considered that. Thank you.
You can install gcc inside a Libertine container and execute it from there.
Or there are ways to hack it into the UT system.
I've do in my tablet with UT from terminal:
phablet@ubuntu-phablet:~$ sudo apt install build-essential
and it works for me.
Unable to locate package. I've already tried a bunch of different ways to get it installed with no success.
It seems some gcc packages are installed (gcc5.1 gcc5.4) so I'm not sure what to do on that front.
@Giiba I'd like to be able to do it directly on the phone. My googlefoo is failing me. Do you have any suggestions on how to hack into the UT system to use GCC?
Do you have any suggestions on how to hack into the UT system to use GCC?
Create a libertine container, and install the packages in libertine. That is the supported way to install legacy apps/tools on UT. See https://docs.ubports.com/en/latest/userguide/dailyuse/libertine.html#shell-access
Main thing to remember here though, is do not install or try to use
sudoinside libertine. If you need a root shell, use
libertine-container-manager execto start a shell in the container as a fake root user. Otherwise use
libertine-launch /bin/bashas in the docs, in the Terminal app, to get a shell as phablet user.
Flohack last edited by
Also keep in mind that compilation puts the flash card under quite a stress, so you might reduce the lifetime of your phone gradually with every compile. I mean bigger ones, not helloworld.c ^^
@dobey - I thought you meant I could do it on the phone or libertine container. Either way, it works! Thank you!
@Flohack - Thank you for your concern. I don't plan to compile everything on the phone, I just wanted to make sure it works and what to expect. I believe it's possible to compile it on my desktop for my phone then move the binary over. I haven't looked into this yet, still working my way though the C++ book.
My goal is to build something like Google Messages (text from a web page) for my PinePhone that's on its way here. I strongly dislike picking up my cellphone when I'm already on my computer.
I believe it's possible to compile it on my desktop for my phone then move the binary over.
Yes, or on your PineBook as you did before. However, the PineBook is probably an arm64 system, and if you did not install the necessary 32-bit packages and tools to cross-compile for 32-bit, then you likely built a 64-bit binary which will not run on a Nexus 5.
@dobey - Thank you!!! this was enough to get me on the right path. I have complied my highlow c++ game on my PineBook and it runs without any issue on the phone.
You guys are very helpful! It would have taken me ages to figure this out on my own. thank you all!
Next I'm Just going to finish my book, look into libdbus and libcurl. Then I'll start reading up on how to build Ubuntu Touch apps. I'll have everything up on gitlab eventually. cheers!
@kjhg84j9 I've used phablet-tools from my computer to unlock my tablet.
I've do "sudo apt update" and "sudo apt install build-essential".
@ereus This is not supported, so it's best not to generally advise people to do this. The rootfs is readonly and limited in space for a reason. In almost all cases, simply doing
apt updatewill result in out of space errors. It is not this simple, not supported, and not advisable.
arubislander last edited by
I would like to add my voice in support of what @dobey said.
I appreciate that the solutions we suggest are 'what worked for us' when we were facing a similar issue. And we feel it is better to give advice that we know will work from our own experience, because we can answer any follow-up questions about that.
But we should consider the potential risk of our proposed solution to leave the device in a state needing a reinstall of the OS to resolve any mistakes.
Not only is that a bad experience for the user, it also gives the impression that the OS is much more fragile than it actually is.
So please, when questions come up where the answer is installing additional command line utilities from the standard repo's. Let's point them to the Libertine documentation first. Libertine works brilliantly for commandline utilities and apps. It's the graphical applications that are more of a hit or miss.