 Hello, this video is part of a series on C programming and we've been looking at cross compiling. We were cross compiling from Linux for Windows. Then we cross compiled for Linux on Linux, but for different architecture such as ARM. And we did that in the last video. We copied our executable over to a Raspberry Pi running Debian ARM and it worked. But let's see what we can do with an Android device. Android device is a Linux device after all, it is running Linux kernel. Even if people will tell you it's not really Linux, it is really Linux. It's got a Linux kernel. And you can compile for it just like you do on any other Linux system. So let's copy over our executable that we compiled last time to an ARM device. I have a phone hooked up here. I'm going to say ADB push and I'm going to push from our bin directory our ARM hello. And I'm going to push that to a directory called data local temp. If you ever need to push something to an Android device, this is a folder that you can push stuff to because a lot of folders you don't have permission to. It's a simple one to remember. And it's been pushed. So now I can ADB shell and I should be able to navigate into that directory. And I should be able to say dot slash ARM hello and it should run. But it doesn't. No such directory. Why is this? Because it's an Android device. No, not necessarily. It's because we have created a linked executable. What does that mean? It's going to look for certain library files, certain lib files on a system. They're not embedded in our application. And this is very common with Linux systems. It's just an efficient way of doing stuff. Instead of having multiple copies of something, we just have one and we tell our applications to look at them. Well, the file system on an Android setup is a little different. The actual library it's looking for is probably on the system somewhere and we can tell it to look for it or we can just embed that library into our executable. So let's go ahead and look at doing that. So I'm going to exit out of my phone. I'm back at my desktop here. And last time we used an application called gcc-arm, or sorry, in my case 10-arm, although the version might be different for you. Is that not what we're working with here? I'm sorry. I'm thinking of the package name, not the executable name. So ARM, Linux, GNU, E, A, B, I, again, look in your package manager for this. You should find packages for it and select the one for your architecture that you're trying to compile to. Because again, we're compiling for ARM, but I've also compiled for MIPS processors before, I think that's how you say it, and a few other processors. And although ARM is one of the most common, there are other processor types out there. And luckily Debian supports almost all of them, so you can actually run Debian on any of these systems if you have the storage for it. Anyway, that was a little side note there. We're going to say gcc, in my case 10-arm, again, the version might be different for you as wherever you have installed. And last time we said this is what we want to compile and we're going to put it in our bin folder and we'll call it, hello, not windows, we're going to call it ARM hello. But I'm going to call this one dash static, excuse me, static. And what we're going to do here is right here, I don't know if it matters, I always put it right here, we're going to say dash static. And that will now compile the required library files into our executable. Great. So that's there. So let's go ahead and push that over. So I'll use our push command again, but I'm going to push our dash static, did compile it there, right? Why is it not auto-completing? Oh, because push does, because ADB doesn't auto-complete, right. Sorry, I thought I messed up there for a second. Okay, it's been pushed over. Let's go ahead and ADB into our shell again. So, oh, shell. So for those of you, so you don't get confused, if it says bullhead here in this particular case, because that's the model of phone here or the code name for the phone, I am now logged into my phone. Anything I run right now will be running on my phone, has nothing to do with my desktop. We're going to move into that directory, and again, I've got two files here. And if I use the file command to display them both, you can see that this is our hello, this is our hello static, they're both ELF, this one is an executable, this one's a shared executable, this is our original one, they're both 32-bit arm processors, this one is dynamic, this one is static, and you can see it's dynamic, it's looking for this particular file, which is, even if it is on my phone, it's not in that location. So now, if I was to run again, our arm hello, it's going to tell us that there's no such file directory. It says that you think it's looking for this, it's actually, I think it's saying that it's missing, this is missing, even though the error message doesn't actually say that. But let's go ahead and do our hello, our arm hello dash static. It says hello world, how great is that? So we have now compiled that. Now, real quick, what I'm going to do, let me get my phone turned on here and unlocked, and what I'm going to do is, I'm exiting out of my phone here, but then I am going to go and run this program here, no, hold on a second, yeah, that is the name of the application dash TS. This is actually saw this on Arthur Reader's YouTube channel. This is an application you can install from your package manager and it uses just ADB to display the screen of your phone on your desktop without having to install anything on your phone. It's just kind of built into the phone already using ADB, I'll do that, and we should get our screen. So this is my phone, I'm logged into Turmux here and I have, I can CD into my data local temp. I'm going to try to run it from here. I have found that it does not work, trying to run it from that directory for some odd reason, but what I can do is I can copy that into my home directory, I can go back into my home directory and I can now run that here. So I'm running that on my phone, in my shell on my phone. So yeah, it's working. We have compiled a C application that I can actually pick up my phone and run. And I didn't have to change the code at all because it is just C code and I compiled it for a Linux system. I just statically embedded all those libraries. So why don't you always do this? Well, efficiency. Let's go ahead and list out from my bin directory here and again all the files, all the code and compiles here are going to be in my GitLab page. Go ahead, check out the link in the description to the GitLab page there. Go to the C folder and then tutorials and you'll see everything in there. If I list out my ARM files here, you can see. Let me go ahead and list it with information. This is our original static or dynamically linked. This is our stack link. Look at the size here. Now they're both very small files, but look at the difference. One is 8 kilobytes. One is 489 kilobytes. That's because your C code needs a lot to run. I mean, you might look at that and laugh about how small it is. But it is substantially bigger. And if every application you compiled, it could add up after a while. We're doing dynamically, this is how big your code is, and then those libraries that take up all this space are only on your system once. And again, I've never done it, but I'm pretty sure that I can do a dynamically linked for something like my Android device, but I'd have to know where those files are. Probably isn't hard to do, but I don't compile too much for my Android device. I use shell scripts mostly, but you could statically compile your applications, copy them to your Android device, and run them right in there from your phone. So if you know how to compile, if you know how to write C code, you know how to write C for an Android device. Now, obviously, if you're actually going to be interacting with the Android environment, you're going to have to learn their APIs and what's the word I'm looking for. What's the word I'm looking for? It's not just API, there's a Android stack, I think is what it would be called. I've never really messed with that, but as far as just doing system level stuff and writing C code that you would write on, you know, as long as you're not creating a GUI, this is all you need. So anyway, I do thank you for watching. Again, check out the links in the description. You can find a link to my website, filmsbychris.com, that's Chris of the K. And also a link to all these files that we are working with here, all these codes, all the resource files, all the compiles there. Go ahead and check those out. I thank you for watching. And I hope that you have a great day. I hope you found this useful. Bye.