 Hello and welcome again this is part of a series on C programming and we might be reviewing stuff so I hope that you checked out the previous videos on this series. What we're going to be looking at today is we'll be looking at cross-compiling stuff for Windows on a Linux system. So far we looked at cross-compiling, we look at cross-compiling and hiding our shell windows that way if you want to make a GUI application or just make a process that runs in the background you can do that without the shell popping up. Next thing we'll look at is on Windows machine you download a executable file from the internet which you should never do and it has a nice little icon because by default it's going to have a little application icon but you want it to have a nice looking icon and that's what we're going to look at doing today. The first thing we need is an icon so let me go ahead and bring over my file manager here and I've added a resource folder here that has a nice little Punisher skull icon it's a PNG but we need an ICO file an icon file so first thing we need to do is convert that to an icon file then we're going to convert it to a C object and then we're going to use our compiler to make that the icon. So first things first I'm going to use image magic to create our icon it should be in your repositories good chance it's probably installed on your system once it's once image magic is installed and again you can use other icon applications if you want I'm going to say convert our skull file and put our icon in our resources folder as well resource it doesn't have to be a resource folder RES it's just short for resources that's where I'm keeping stuff dot ICO and you can even do dash color 256 if you want to make sure it has the 256 color palette there and I did something wrong that was color you know let's just leave that out because I don't think it's really necessary there we go now again if I file out everything in our resources folder you can see that we have our PNG here but then we also have an icon file for Windows icon resource but it's not a C resource file it's not a C object kit so we need to convert that to be a C object so I'm going to since we installed in the previous videos our Ming W32 and again or 64 if you missed that just apt-situde or whatever package manager using search for Ming W and sorry search for Ming W and on a Debian based system it's going to be Ming W-W64 as of right now the name might change in the future but look for something name something like that go ahead and install that once that is installed I can say I6 and hit tab to autocomplete if I tab a few more times I can see all these what we want is this very last one here I686-W64-Ming W32 and it's the wind rest so the wind resource the Windows resource application is going to take our input file and it's going to create an object of it actually but before we do that I have a file in here again all these files are up on my GitLab page there's a link in the description of this video to that but we are going to list out our files here you can see I have a file called main.rc and if I cat that out so we can see what's in it you can see there's just one line in there ID icon all capital space and then the name of our file so it's in a resource folders slash icon dot icos so we need that it's just a plain text file and once we do that then we can do our I686-W64 the wind rest one so we're creating a Windows resource here dash O and we are going to say resource folder and I'm going to call it icon dot O so and then we're going to say main.rc so what this is saying is use this application look at this file for what you need to do we're going to be looking at and that file says look at this icon file we're saying we're going to create an object and we're going to output it to this file and we did that no errors that's good to go again if I file my resources file will just tell us what type of each file is by looking at the header of it you can see again we have our icon file here this Windows icon we have our PNG which is a PNG file and then we also have this right here it's an icon.io it's an object file and it is stripped blah blah blah everything seems good so at this point you can delete your icon file and delete your PNG all we need is this icon dot o file this object file and we're going to do I686 mean GCC just like we did before everything we're going to do just like we did before I'm going to give it our Windows start URL so that it will start a URL for us I'm going to say resources our icon file dot o so saying this is an object file include this in the compilation we're going to say dash o for our output I'll put it in our bin folder and I'll just call it I actually already compiled this but icon underscore win hello dot exe and this would compile it and a shell would pop open if we want to hide that shell we can say dash M windows no errors and now I can file bin icon win hello and you can see that it compiled it a Windows MS Windows application it thinks it's a GUI application even though it's not just showing the windows going to be hide hidden when it starts off and when we look at that on a Windows machine the icon for that exe should look like our PNG icon now before we look at that on a Windows hardware actual Windows machine I mentioned someone's going to ask well how do you do this for Linux how do you embed an icon so that in your Windows file manager which by the way if I do go into my file manager here and look at our files you can see that it doesn't show up as that and if I go to our compiled application you can see that my particular file browser is showing that these icons for the Windows executable and then these other executions just showing us files and the thing is and I'm not saying there's never a case there's there might be file browsers out there that will show the Windows icons but for as far as Linux applications compiling an application for Linux and embedding an icon not aware of a way to that that's because there's really no reason to do this Linux does it a different way my opinion a better way which I can get more into in a future video of people request but basically you should never just download an executable and run it so you should never be looking directly at the executable like this so you shouldn't be looking at the icon for this usually if you're going to install an application you should be installing it for installing it from a trusted resource just trusted server somewhere and it should unload the package and all the necessary files to your system and then when you go to your desktop or file browser there is going to be an icon there but that's a link file which is just a plain text file telling it where the icons are what applications run and even gives you more options for language and stuff like that and it's a much more efficient way of doing things and also if you can also link stuff on a window so when I embed an icon like this into the executable it's always going to show that icon and by the way you can make icons of multiple sizes in one file we didn't do that it may be something I'll look into but on the next thing you can make the icon look at wherever you want to on the link on a windows machine you can create a link on your desktop the links to it but it's an ugly binary file that you need special libraries to create instead of just creating a text file so that's just quick little rant on that because someone is going to ask how you do this on a Linux machine for links executable and the thing is you don't because it's it's it's just a horrible way of running applications in general in my personal opinion you can disagree anyway let's look at this on actual windows hardware okay stop and rewind for a second uh you have to forgive me because I do not have a windows machine readily available in my house sometimes I'll get a virtual machine going for testing stuff but I want to test this on real hardware and I recorded a couple of videos where I compiled for windows and then I a couple days later went to some place where there was a windows machine to test them out and record them for you and if you watched the previous video about hiding windows when they run I made a mistake in that if you compile even if you hide the window using the dash uh M windows option uh if you use a system call it's still going to show a shell or a console for a moment there and in this video I was using code I wrote that was supposed to open up the red browser using a system call command so there was a shell popping up and not that that's the main focus of this video I wanted to go back and do this uh properly so uh instead of compiling that code I'm just going to pile our right file code so again it's from two tutorials zero three tutorials ago where we just open up a text file and append hello to it and then close that file and exit out of the application um so again we're just going to run the same command as before I'm just giving a different c file I'm going to give it the same uh icon object that we created before and going to create an executable called uh icon win hello dot exe we will compile that and I can uh run the file command here on linux to look at that and it does say that it's a gooey um so a a graphic user interface uh ms windows application it's an executable let's go ahead and run that on actual windows hardware now okay so I'm at a windows machine here and um I'm going to go to my git lab page download that executable which is compiled on linux for windows there it is you can see the icon when it downloads we're going to show it in a folder you can see the icon there you can see the last file we downloaded without the icon giving the default icon I deleted the text file that we generated before again I'm going to tell it yes yes I want to open this that's why I clicked on it and you can see it created a text file if I open that up it says hello inside I can click on it a couple of times and you can see no window pops up and it says hello a number of times every time I click on it it depends to that file and if I go over here and I try to uh make the icons larger oh I missed set to extra large icons you can see the default windows executable icon if you don't give it an icon and then our expil which does have an icon and uh that is pretty much it so again uh you can go to my website filmsbychrist.com that's chris the k there's a link in the description you can search through my videos and my programs and notes and you can also support me uh with paypal and patreon all these links are also in the description of the video and also for the code that was in the news this in this tutorial and basically this whole series if you go to getlab.com forward slash metal x1000 you can get there by clicking on this link right here then look for my project called my bin which is just a series of random scripts I've written over the years there's a c folder and uh tutorials and there's all that code and here's the one that we use today so here's the one that I was originally trying to use in this series or in this particular video I did uh well actually I changed it even when I was testing things out uh originally this said start uh and gave it a URL which would open up the default web browser in uh you know for your system to that web page but I was doing a system call even though I was calling a GUI application which would cause a shell to pop up at least momentarily so that's why we went back and I should actually change this code back to what it was since it's labeled uh start URL but we use the right command just because there's no system calls in here and that's pretty much it I do thank you for watching as always I hope that you have a great day