UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Compile C++ on phone

    Scheduled Pinned Locked Moved General
    14 Posts 7 Posters 1.6k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • K Offline
        kjhg84j9
        last edited by kjhg84j9

        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?

        Thanks!

        G 1 Reply Last reply Reply Quote 0
        • G Offline
          guru @kjhg84j9
          last edited by

          Un-tar a complete Linux and chroot into it.

          1 Reply Last reply Reply Quote 0
          • K Offline
            kjhg84j9
            last edited by

            Neat, I never considered that. Thank you.

            1 Reply Last reply Reply Quote 0
            • G Offline
              Giiba
              last edited by

              You can install gcc inside a Libertine container and execute it from there.

              Or there are ways to hack it into the UT system.

              1 Reply Last reply Reply Quote 0
              • E Offline
                ereus
                last edited by

                I've do in my tablet with UT from terminal:

                phablet@ubuntu-phablet:~$ sudo apt install build-essential
                

                and it works for me.

                K 1 Reply Last reply Reply Quote 0
                • K Offline
                  kjhg84j9 @ereus
                  last edited by kjhg84j9

                  @ereus

                  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?

                  dobeyD E 2 Replies Last reply Reply Quote 0
                  • dobeyD Offline
                    dobey @kjhg84j9
                    last edited by

                    @kjhg84j9 said in Complie C++ on phone:

                    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 sudo inside libertine. If you need a root shell, use libertine-container-manager exec to start a shell in the container as a fake root user. Otherwise use libertine-launch /bin/bash as in the docs, in the Terminal app, to get a shell as phablet user.

                    1 Reply Last reply Reply Quote 0
                    • flohackF Offline
                      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 ^^

                      My languages: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        kjhg84j9
                        last edited by

                        @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.

                        Cheers!

                        dobeyD 1 Reply Last reply Reply Quote 0
                        • dobeyD Offline
                          dobey @kjhg84j9
                          last edited by

                          @kjhg84j9 said in Complie C++ on phone:

                          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.

                          1 Reply Last reply Reply Quote 0
                          • K Offline
                            kjhg84j9
                            last edited by

                            @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!

                            1 Reply Last reply Reply Quote 0
                            • E Offline
                              ereus @kjhg84j9
                              last edited by ereus

                              @kjhg84j9 I've used phablet-tools from my computer to unlock my tablet.
                              And then,
                              I've do "sudo apt update" and "sudo apt install build-essential".

                              dobeyD 1 Reply Last reply Reply Quote 0
                              • dobeyD Offline
                                dobey @ereus
                                last edited by

                                @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 update will result in out of space errors. It is not this simple, not supported, and not advisable.

                                1 Reply Last reply Reply Quote -1
                                • arubislanderA Offline
                                  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.

                                  πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                                  Happily running Ubuntu Touch
                                  Google Pixel 3a (20.04 DEV)
                                  JingPad (24.04 preview)
                                  Meizu Pro 5 (16.04 DEV)

                                  1 Reply Last reply Reply Quote 1
                                  • First post
                                    Last post