Page 1 of 2
Am I using the right gcc build?
Posted: Fri Mar 14, 2014 1:07 pm
by boemba
Hello, I tried following this tutorial using windows 8:
http://wiki.osdev.org/Bare_bones
I downloaded MinGW, ticked gcc and the mingw32 base:
Then I set the system variable path to E:\MinGW\bin:
I made a bootloader called boot.asm, made in NASM:
http://wiki.osdev.org/Bare_Bones_with_NASM
I made a kernel in c, called kernel.c
However, I cannot make the c file, because I don't have my gcc configured to i586.
I have read that I have to do this everywhere, but have no clue on HOW to do it.
I read this entire page but could not find out how to configure it to "i586" for windows:
http://wiki.osdev.org/GCC_Cross-Compiler
So when I run a command, I get this:
It obviously doesn't understand the command.
Please help! I have searched on the wiki, on google and on the forum but can't find any info on this.
Thanks,
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 1:08 pm
by boemba
By the way, I can use the command
Code: Select all
gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
But at the end, when trying to link the kernel and bootloader together, it gives the error that the bootloader cannot find "kernel_main" while it obviously does exist in kernel.c
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 1:36 pm
by madanra
Caveat: I have not used a cross-complier myself (my ventures into OS development have been assembly-only so far), so this post is from what I've read lurking on these forums rather than experience. I expect someone more qualified will reply, but hopefully this will help in the meantime
First thing I can see is that you're still trying to run your host's gcc, rather than your cross-compiler version of gcc. That's why you're getting the error message
Code: Select all
gcc: error: i586-elf-gcc: No such file or directory
as i586-elf-gcc is the cross-compiler you've compiled, not a parameter to gcc. So you should be running something like:
Code: Select all
i586-elf-gcc -c kernel.c -o kernel.o -Wall -Wextra
ie. i586-elf-gcc is the compiler you're running.
boemba wrote:I read this entire page but could not find out how to configure it to "i586" for windows:
You're not trying to configure it for Windows - you're trying to configure it for your operating system. The host is Windows, but none of the configuration is Windows specific - well, there may be some minor differences between building on Windows and Linux, but the important thing is you are configuring gcc to target your operating system.
Regarding the problem with linking, the first thing I thought of was that compilers often munge names. You could check with nm what is actually in kernel.o. I could be way off on this one though!
HTH!
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 1:52 pm
by boemba
Thanks for your reply!
madanra wrote:Caveat: I have not used a cross-complier myself (my ventures into OS development have been assembly-only so far), so this post is from what I've read lurking on these forums rather than experience. I expect someone more qualified will reply, but hopefully this will help in the meantime
First thing I can see is that you're still trying to run your host's gcc, rather than your cross-compiler version of gcc. That's why you're getting the error message
Code: Select all
gcc: error: i586-elf-gcc: No such file or directory
as i586-elf-gcc is the cross-compiler you've compiled, not a parameter to gcc. So you should be running something like:
Code: Select all
i586-elf-gcc -c kernel.c -o kernel.o -Wall -Wextra
ie. i586-elf-gcc is the compiler you're running.
Yes, I suspected that i586-elf-gcc had to be a filename, but I can't find it anywhere in my directory.
I thought that by installing gcc via MinGW Installation Manager would be "building" it, but probably not as I can't find "i586-elf-gcc" in the MinGW directory.
Regarding the problem with linking, the first thing I thought of was that compilers often munge names. You could check with nm what is actually in kernel.o. I could be way off on this one though!
Do you think that if I used "void kmain" instead of "void kernel_main" it would fix the problem? I will try it out soon but I have no idea if that will work since I haven't even specified the target architecture i586.
You're not trying to configure it for Windows - you're trying to configure it for your operating system. The host is Windows, but none of the configuration is Windows specific - well, there may be some minor differences between building on Windows and Linux, but the important thing is you are configuring gcc to target your operating system.
I should have said: "how to configure gcc to target the i586 architecture on windows?". That is actually the main question now.
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 2:17 pm
by madanra
boemba wrote:Yes, I suspected that i586-elf-gcc had to be a filename, but I can't find it anywhere in my directory.
I thought that by installing gcc via MinGW Installation Manager would be "building" it, but probably not as I can't find "i586-elf-gcc" in the MinGW directory.
No, i586-elf-gcc is the cross-compiler you need to build from source. MinGW will only install a toolchain that targets Windows.
boemba wrote:Do you think that if I used "void kmain" instead of "void kernel_main" it would fix the problem? I will try it out soon but I have no idea if that will work since I haven't even specified the target architecture i586.
I don't think that will make any difference.
boemba wrote:I should have said: "how to configure gcc to target the i586 architecture on windows?". That is actually the main question now.
Indeed - and that is the topic of
GCC_Cross-Compiler
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 2:23 pm
by boemba
madanra wrote:boemba wrote:Yes, I suspected that i586-elf-gcc had to be a filename, but I can't find it anywhere in my directory.
I thought that by installing gcc via MinGW Installation Manager would be "building" it, but probably not as I can't find "i586-elf-gcc" in the MinGW directory.
No, i586-elf-gcc is the cross-compiler you need to build from source. MinGW will only install a toolchain that targets Windows.
boemba wrote:Do you think that if I used "void kmain" instead of "void kernel_main" it would fix the problem? I will try it out soon but I have no idea if that will work since I haven't even specified the target architecture i586.
I don't think that will make any difference.
boemba wrote:I should have said: "how to configure gcc to target the i586 architecture on windows?". That is actually the main question now.
Indeed - and that is the topic of
GCC_Cross-Compiler
I linked to that in my original post but couldn't understand it..
Windows users need to set up a Unix-like enviroment such as MinGW or Cygwin. It may well be worth looking into systems such as Linux and see if they fit your needs, as you commonly use a lot of Unix-like tools in operating systems development and this is much easier from a Unix-like operating system. If you have just installed the basic Cygwin package, you have to run the setup.exe again and install the following packages: GCC, Make, Flex, Bison, and Diffutils.
MinGW + MSYS is an option, and as it addresses the native Windows API instead of a POSIX emulation layer, results in a slightly faster toolchain. Some software packages will not build properly under MSYS as they were not designed for use with Windows. As far as this tutorial is concerned, everything that applies to Cygwin also applies to MSYS unless otherwise specified. Make sure you install the C and C++ compilers, and the MSYS Basic System.
Note: Cygwin includes your Windows %PATH% in its bash $PATH. If you were using DJGPP before, this could result in confusion as e.g. calling gcc on the Cygwin bash command line would still call the DJGPP compiler. After uninstalling DJGPP, you should delete the DJGPP environment variable and clear the C:\djgpp entry (or wherever you installed it) from your %PATH%. Likewise, it might be a bad idea to mix build environments in your system PATH variable.
This is what it said about windows - I downloaded MinGW but didn't get i586-elf-gcc cross-compiler.
I also couldn't understand much about "The build", I might be wrong but it seems to be linux-specific?
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 2:26 pm
by madanra
boemba wrote:I linked to that in my original post but couldn't understand it..
Windows users need to set up a Unix-like enviroment such as MinGW or Cygwin. It may well be worth looking into systems such as Linux and see if they fit your needs, as you commonly use a lot of Unix-like tools in operating systems development and this is much easier from a Unix-like operating system. If you have just installed the basic Cygwin package, you have to run the setup.exe again and install the following packages: GCC, Make, Flex, Bison, and Diffutils.
MinGW + MSYS is an option, and as it addresses the native Windows API instead of a POSIX emulation layer, results in a slightly faster toolchain. Some software packages will not build properly under MSYS as they were not designed for use with Windows. As far as this tutorial is concerned, everything that applies to Cygwin also applies to MSYS unless otherwise specified. Make sure you install the C and C++ compilers, and the MSYS Basic System.
Note: Cygwin includes your Windows %PATH% in its bash $PATH. If you were using DJGPP before, this could result in confusion as e.g. calling gcc on the Cygwin bash command line would still call the DJGPP compiler. After uninstalling DJGPP, you should delete the DJGPP environment variable and clear the C:\djgpp entry (or wherever you installed it) from your %PATH%. Likewise, it might be a bad idea to mix build environments in your system PATH variable.
This is what it said about windows - I downloaded MinGW but didn't get i586-elf-gcc cross-compiler.
I also couldn't understand much about "The build", I might be wrong but it seems to be linux-specific?
Nothing in there is Linux-specific, except the suggestion of /usr/local/cross as a possible install location. However, it is all Bash-specific, which is why you need msys or cygwin installed, so that you have a Bash shell on Windows.
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 2:32 pm
by boemba
madanra wrote:
Nothing in there is Linux-specific, except the suggestion of /usr/local/cross as a possible install location. However, it is all Bash-specific, which is why you need msys or cygwin installed, so that you have a Bash shell on Windows.
Okay, I guess MinGW doesn't have the bash feature? I will try to install cygwin or msys then - thanks for your help.
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 2:38 pm
by Pancakes
Just an idea:
But, you might find Linux being a more comfortable development environment. You can use VirtualBox (google it - also free to use) and setup a Linux distribution. Also, you can share you files from Windows with it using the tools provided and mount that directory in linux.
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 2:42 pm
by boemba
Pancakes wrote:Just an idea:
But, you might find Linux being a more comfortable development environment. You can use VirtualBox (google it - also free to use) and setup a Linux distribution. Also, you can share you files from Windows with it using the tools provided and mount that directory in linux.
I actually have ubuntu on virtualbox, but I find I'm not comfortable enough with the terminal yet, to do this.
I already managed to install NASM on it though so I might try gcc too, thanks for the suggestion.
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 3:00 pm
by madanra
boemba wrote:Okay, I guess MinGW doesn't have the bash feature? I will try to install cygwin or msys then - thanks for your help.
Ah, sorry, I should have been more clear - msys and MinGW go together, msys provides the Bash shell & main utilities, MinGW provides a compiler that targets Windows. So you choose between msys+MinGW and cygwin. cygwin has many packages available, including a shell, utilities, and a compiler.
boemba wrote:I actually have ubuntu on virtualbox, but I find I'm not comfortable enough with the terminal yet, to do this.
I already managed to install NASM on it though so I might try gcc too, thanks for the suggestion.
You'll be using the same shell (Bash) to do the compiling whether you're using Windows or Linux, so you'll need to be able to use the terminal to compile a cross-compiler on Windows or Linux.
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 7:39 pm
by hometue
Just a suggestion, if you are using virtualbox, you might want to install Debian or other linux distro. Not saying Ubuntu is bad, but its bloated, unless you have a good enough computer (more or less pointing about the RAM, you need enough RAM, also you need good processor). Also, if you don't know (I am guessing from the posts), most (actually I know its all, but there are always exceptions) linux distro come with gcc. Run the command gcc-v . However its not a cross-compiler so you will have to build your own. I can look for the script I run to mount the files in the host system if you want.
P.S.: I think you shouldn't be using MinGW to compile, it can be kinda screwed up. Well...at least mine is...
Re: Am I using the right gcc build?
Posted: Fri Mar 14, 2014 8:18 pm
by Octocontrabass
MinGW works just fine, but you haven't installed all of the packages you need.
First, you must install msys-base.
Once that's installed, run msys.bat (if you installed MinGW on drive D, you'll find it at "D:\MinGW\msys\1.0"). It will open something that looks like command prompt; that is your terminal. All of the commands that you see on the wiki need to be entered there. They will NOT work if you use Command Prompt.
Next, open your msys home folder ("D:\MinGW\msys\1.0\home\your_name_here"). When you see references to "$HOME", that's what it's talking about. (When it says "$HOME/src", it's talking about a folder called "src" inside that folder.) This is where you'll be putting the source code that you download.
Now, follow the directions in
GCC Cross-Compiler. If you have any further questions, feel free to ask.
Re: Am I using the right gcc build?
Posted: Sat Mar 15, 2014 9:09 am
by boemba
Thanks a lot for the replies guys, it is all a lot more clear now.
I read in the wiki that MinGW, Cygwin etc emulate the unix environment in windows, but I did not read anywhere that that includes the terminal. Thanks for clearing everything up.
------------
I installed the msys-base, started the MinGW terminal, and created the folder "build-binutils" in the folder "src"
However, when using the commands
and
the terminal responds with the error that there is no makefile.
I don't understand where I have to get the makefile from.
On the page
http://wiki.osdev.org/GCC_Cross-Compiler it says I have to download source files for it, so I downloaded binutils from
https://gmplib.org/ and put them in the "build-binutils" folder.
I couldn't find this error on google.
Re: Am I using the right gcc build?
Posted: Sat Mar 15, 2014 9:27 am
by Brynet-Inc
boemba wrote:../binutils-x.y.z/