Building a Linux Kernel with Visual Studio 2010 [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Does anyone have step-by-step instructions on how to build a Linux kernel using Visual Studio 2010?
I've tried to search for the solution to this question directly, but no joy. A few things I have been able to find out:
The Linux kernel is built using the GNU C compiler, so a prerequisite would be to build a Windows GNU C compiler, in order to compile a Linux GNU C compiler. I realize the GNU C compiler source code is available from GNU.org, but has anyone actually built the GNU C compiler for Windows using the Microsoft Visual Studio 2010 C/C++ compiler?
Once the Linux GNU C compiler is made, I can use it to build the Linux kernel, along with any other Linux-based software needed to get a Linux system up and going. This is what I got from www.linuxfromscratch.org
Some of you may be wondering why I don't simply download a pre-compiled GNU C compiler for this? The environment I'm working in is completely separated from any outside network. Even sneaker-net is not allowed. Every bit of software will have to be compiled from source, and those sources will have to be typed in by hand. It's inefficient, but it's also paranoid-secure. (Don't ask, I'm not the boss...)
Anyway, we're looking at bringing up in-house Linux boxes, but we're starting with Windows 7 and Visual Studio 2010. Can someone please advise how we can turn all that re-typed source code into a working GNU C compiler for Windows? And also for Linux?
Thanks for any advice!

I think that Ken Thompson's "Reflections on Trusting Trust" explains very well how futile and not paranoid enough is this idea.
You can't trust
code that you did not totally create
yourself. (Especially code from
companies that employ people like me.)
No amount of source-level verification
or scrutiny will protect you from
using untrusted code.
How do you know that the compiler you are going to use to build GCC is secure if you didn't compile it yourself from source? And the compiler you used for that?
You need to type in by hand the machine code for a compiler to bootstrap your 100% secure environment. Only then can you trust compiled source code, whether you typed it in by hand or not.

Fact: you need gcc to compile a kernel.
Fact: you need kernel source to compile a kernel.
Once you have those two, you can bootstrap a working kernel, targeted for any platform you wish.
You can do all this on any platform you wish. For example, you can build a Linux kernel on Windows. You can just as easily build a Linux kernel for ARM or PPC on Windows.
But you've got to have the kernel source and the gcc compiler to get started.
And both the kernel source as well as gcc source depend on literally thousands headers and .c files. They're simply not practical to key in by hand.
IMHO...

If you're going to build a kernel, use a Linux distribution. There is no point in building one under Windows. Even if you'll be making your own Linux, still use Linux for that.
You could always try cygwin, but I doubt that will do you much good, even if you install all the packages.

Fabrice Bellards tcc is able to compile Linux.
It's so small you can probably compile it in Visual C++ (or modify until it works).
You could also try his qemu to simulate a computer.
Recently he even implemented a x86 virtual machine in Javascript, so you can run everything within your browser.

Even sneaker-net is not allowed. Every bit of software will have to be compiled from source, and those sources will have to be typed in by hand. It's inefficient, but it's also paranoid-secure.
Tell your boss that having someone type source code by hand is going to do nothing but induce bugs. If they want Linux boxes, then they're going to have to use the source code for Linux. You guys didn't type in all the Windows 7 source code by hand either, did you? The kernel is some 13.5 million lines of source code. There's no way you're going to be able to type that all out without inducing a ton if typo-related bugs, and that's less secure than just copying the source.
Your boss needs to get it through his head that even just typing that much code, even if the person in question was a 100% perfect typists, would take years.

By typing the whole code you mean copying/retyping every single line of code?
Please, allow me to ask, how different of the original code is this going to be?
If you're just copying, you're not fixing bugs nor checking possible vulnerabilities. Are you? I'd rather spend the respective amount of time reviewing the actual code and reporting or fixing the problems you occasionaly find.

Okay. That is almost impossible.
How you could do it:
Download virtualbox
Download an Ubuntu iso
Install Virtualbox
Create and install an Ubuntu Virtual Machine
On that virutal machine's terminal:
sudo apt-get build-essential
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.2.tar.bz2
tar vxjf linux-2.6.39.2.tar.bz2
cd linux-2.6.39.2
make menuconfig ; make
Or something like that...

Assuming this question isn't a troll (is that possible?)... Maybe you're planning to OCR the source into your system, like how PGP used to get around encryption software export restrictions.
But I don't think you'll have any luck building GCC using MSVC, regardless of how many monkeys might be typing in the source. From http://gcc.gnu.org/install/specific.html:
GCC will build under Cygwin without modification; it does not build with Microsoft's C++ compiler and there are no plans to make it do so.
Of course, if you do manage to ever get GCC onto the system under the conditions you give, and you get the Linux kernel source there somehow, I think you'll run into difficulties cross compiling Linux under a Windows-based GCC cross compiler. If nothing else, the Linux source tree and build environment depend at least a little bit on the case-sensitive nature of Unix file systems (ie., they depend on the fact that fielname can differ only in the case of characters). Windows doesn't deal well with filename that differ only by case (I think that NTFS can be configured somehow to support them, but the Win32 subsystem will almost certainly be hopelessly confused).
I'm sure there are other hurdles.

Related

How can I compile ANSI C99-based MEX code delivered with Linux makefiles under Win64 MATLAB?

It seems I've got a real problem here due to my lack of any knowledge about Linux systems:
I have downloaded some open source code, which
is written in C
uses complex.h, so I assume it is ANSI C99
comes with makefiles designed for compilation under Linux systems
provides interfaces to IDL, MATLAB, Python etc.
I am indeed familiar about compiling C/MEX files under Windows-based MATLAB environments, but in this case I don't even know where to start. The project is distributed in several folders and consists of dozens of source and header files. And, to begin with, the Visual Studio 2010 compiler I've used to compile MEX files until now does not comply with the C99 standard, i.e. it does not recognize the complex.h header.
Any help towards getting this project compiled would be highly appreciated. In particular, I have the following questions:
1) Is there any possibility to automatically extract compilation information from the MEX files and transfer it to Windows reality?
2) Is there any free compiler being able to compile C99 stuff, which is also easy to embed in MATLAB?
I have done this (moved in-house legacy code inc. mex files to Win64). I can't recommend the experience.
You will have to recompile, no way around it.
Supported compilers for mex depend on your MATLAB version
This File Exchange entry for using Pelles C may be a starting point (if it works with your version of MATLAB).
I am guessing that there is a main makefile which then works through the makefiles in the subdirectories - have a read through the instructions for compiling under Linux, it will give you some idea of what's going on and may also discuss what to do if you want to change compiler. Once you've found a compatible compiler, the next stage is to understand what the makefiles are doing and edit them accordingly (change paths, compiler, compiler flags, etc.)
Then, from memory (it was a while ago), you get to enjoy a magical mystery tour through increasingly obscure compiler errors. Document everything because if you do get it working, you won't be in a mood to do this twice.
MATLAB R2016b on Windows now supports the MinGW compiler. I'm successfully using this to compile code written primarily for Linux/gcc. I installed this from the Add-On menu in MATLAB (search MinGW).
For my case, I'm building with the legacy code tool. The only thing I needed to do differently than normal was to tell the compiler to support c99 via a compiler flag. This does the trick:
legacy_code('compile', def, {'CFLAGS=-std=c99'})
I had trouble getting the flag command just right (I had some extra quotes that apparently broke things), and asked The MathWorks, so credit is due to their support team for this.
If you are using mex, I would expect to do something very similar.
I would guess that the makefiles are irrelevant for your application; you will need to tell the mex or legacy_code function about all of the files necessary to build the whole application or link against pre-built libraries (which it sounds like you don't have).
I hope this helps!

How to cross compile C code for an ia188em chip

I inherited an old project that uses an Innovasic ia188em processor (previously AM188 from AMD). I will likely need to modify the code, and so will need to recompile. Unfortunately, I'm not sure which compiler was used previously (it compiled into a .hex file), and searching through the source code (and in particular the header files) doesn't seem to indicate it either.
I did see one program that could work, but I was wondering if anyone knew of any free programs that might do this. I saw some forums where people said they thought either an old Borland compiler or Bruce's C Compiler may work with 80188 chips (which I assume my chip falls under?), but nothing concrete. I failed to compile with Borland C++ 5 when I tried, though I admit I probably didn't have it set up correctly.
This is for an embedded board (i.e. no OS). I don't program too often, so my compiler knowledge is limited. I mostly just write simple C programs and compile with gcc under linux. Any help is appreciated.
Updated 10/8: I apologize, I was looking at both this code, and the PC side code that talks to the embedded board, and got mixed up. The code for the ia188em (embedded board) is actually C (not C++). Updated title to reflect that. I'm not sure if it makes a huge difference or not.
You'll need a 16 bit "real mode" x86 compiler. If your compiler is a DOS targeted compiler, you will need some means of generating a raw binary rather than than MS-DOS load module (.exe), this may be possible through linker options or may require a non-DOS linker.
Any build scripts or makefiles included with the project code might help you identifier the toolchain used, but the likelihood is that it is no longer available, and you'll need to source "antique software".
When I used to do this sort of thing (1985 -> 1990) I used the intel toolchain, now long obsolete and no longer available from intel. The tools required were
iC-86 - The compiler
link-86 - the linker
loc-86 - the image locater.
There is some information on these tools at a very old site here.
Another method that was used at the time was to process the .exe file produced by a Microsoft standard real mode PC compiler (MS-Pascal was the language used on that project) into an absolutely located image that could be blown into EPROM. The tool used for the conversion was proprietary to the company so I have no idea whether there is an equivalent available

How do I setup a C environment on Windows (and maybe Linux compatible, too)

Short version of question: How do I get started with C programming? Note that I am not asking for a tutorial on learning C language (I can learn that easy enough). I need to setup the environment (I hope I'm asking this question clearly). Here's what I mean:
For my math thesis, I need to write a program in C on Gentoo Linux, using a library called CVODE/SUNDIALS. There is nobody (it seems) in my department who can help me set this up - my professor has left the computer work 100% to me because I have some programming background and he's a math geek. But my experience is with scripting languages (think VBA) and not full, powerful programming languages where you have to link the compiler and libraries, etc. like C.
There is no development environment on the Linux cluster - or at least not that's friendly, and has a debugger - that I've found. So, what I need to figure out how to setup a C programming environment with CVODE library on my PC (Win 7 x64, at little to no cost.
I have found plenty of tutorials on programming in C. I looked up Eclipse, which I have a little bit of experience with, as a development environment, but it's instructions say you need to install a compiler, too.
What I would like is someone to tell me, in simple language that I can understand (which might be the most difficult part of this question) the big picture of what I need and what to do (and maybe even links to where I can find what I need) to set up a C environment with CVODE. If the information is Windows/Gentoo Linux cross platform, even better.
Thank you.
P.S. I did search the site and saw lots of "How do I setup" quesitons, but no C one. Because I know someone will yell at me for that. Also, I don't want to have a convo about whether to use C#, C++, Java, etc. That just complicates the issue - and I need to get this done.
Edit: I have learned a little more since this question and now realize that I left out a key part of the question. The CVODE library and Linux cluster at school use MPI - parallel programming - which is not available on your average, run-of-the-mill PC. So all development must be done directly on the cluster.
Linux: Simple way is to install gcc or g++.
You can write your code in your plain text editor (nano, vim, gedit, kwrite, etc)
Save your file in .c or .cpp extention and type in terminal
gcc filename.c
or
g++ filename.cpp
You said that you want to write c code on Gentoo Linux, as i understand you're not familiar with Linux? The best choice in this case is to:
Install virtualbox in your windows machine (https://www.virtualbox.org/), it's a free software that let you emulate in your desktop another systems like Linux...
Install Gentoo linux on virtualbox, there are a lot of tutorials on the net, for example this video: http://www.youtube.com/watch?v=DUf_1wAPeyA
When you install Gentoo Linux on virtualbox you have all you need to develop C (gcc compiler, gdb debugger...)
Now you can download your library, and decompress it
In general all (Good) Linux libraries come with a 'README' file that contain all instructions for installing the library.
I think you need to do this:
./configure --prefix=/DIRECTORY_YOU_WANT_TO_INSTALL_THE_LIBRARY
make
make install
You can now play with C and you new library, like this:
suppose you create a new file test_lib_ CVODE.c you can compile it like this:
gcc -Wall test_lib_ CVODE.c -o test_lib_ CVODE -lcvode
I assume that the installed library is named libcvode.so
If you have any questions, you can always get help here.
Regards.
I think you should use Code::Block in Linux, it is very similar to Window's Code::Block and it is very easy to debug and other things.
These were all useful answers. I tried pursuing each of them at least a little bit. However, the only reasonable solution seems to be to use emacs on a terminal window. This is because I'm using MPI - yes, I know I didn't mention that in the OP - which can only be done on a cluster.
I am new to this environment and was not aware of the MPI or the affect it would have on my attempt to develop.
I believe I can do better than this if I can figure out X/Windows using Cygwin. But I am a long way from that.
Thanks all for your effort and sorry I can't really award a best answer (I guess).

OpenMP not in NetBeans IDE 7.0

The title is fairly self explanatory... isn't anywhere to be found in the version I have (the latest), and all searches on the web have turned up little to nothing in the way of real solutions. There is only a pdf file which explains that omp flags must be marked in the C compiler I use, but I can't even get that far because I can't find the library anywhere!
Is there just a way to pull the library from somewhere and load it in? Or do I need an entirely new gcc file for my IDE to pull from, and if so, where do I get it?
EDIT: Still no luck searching. I'm also willing to work with a different IDE similar to NetBeans... preferably one that uses the Cygwin compiler set as well. If anyone has any suggestions on what I could use that would support OMP, I would be more than willing to entertain them.
Oracle Solaris Studio on Solaris (SPARC and x86) and Linux (x86) provides an IDE with C/C++/Fortran compilers with OpenMP 3.0 enabled, and a debugger and performance analyzer that understand OpenMP.
http://www.oracle.com/technetwork/server-storage/solarisstudio/index.html
And, it's a free download and free to use.

using Linux instead of UNIX to compile c code for CS course

A CS course I'm taking online suggests students compile their source code and run tools like valgrind on the OS UNIX. I'm completely new to UNIX, Linux, their tools, and coding in c. I've made some attempts at installing FreeBSD 8.1 on VMWare Player 3.1.3, and even managed to get VMWare Tools running. But the FreeBSD documentation has led me down many dead-ends in accomplishing common tasks i.e. mounting an NFS or USB device. It turns out that the packages I need to make this happen aren't installed or configured, and I don't see any straight answer on how to install them.
So, if I'm using UNIX only as a tool to run gcc, g++, valgrind for this CS course, and these can be run on Linux instead, it seems like I can get the job done faster using Ubuntu Linux.
Can Linux be used to compile and run c code identically on UNIX, if compiled on Linux? Or if not, what are the differences to look for?
Thanks
For the novice-level C programmer such as OP, the difference of environment is negligible. Go ahead with Linux.
I think for purposes of the course you could run your programs and tools on Linux,
but I guess the reason your teacher wants you to use FreeBSD is so that you learn other things besides just coding up your problems
The two should be effectively the same. The only major difference you might see would be due to different versions being used. I would check to see what versions of gcc, g++ and valgrind the teacher is having you use, and make sure that you have the same version running on your install of Linux.
You can also use MinGW or Cygwin. You mentioned VMWare, so I'm guessing you're trying to just get an environment up and running in a windows environment. They both allow you to use the compiler and some of the tools without a full install of a Linux based system. In a CS course they would be more than enough.
The main differences too look for:
Compiling C / C++ is not machine independent. You need to have a small environment to compile on UNIX anyway if you need to submit compiled programs to your professor.
C / C++ is rather portable if you don't use anything that's non-portable. It's very hard to verify that you didn't use something that's different between the two machines, so you may wish to compile on UNIX to verify you didn't let an unavailable library (or an specific to the OS procedure, argument, behavior, bugs, etc.) slip into your code.
The vendor of make between the two machines may differ. This means that while the core of make will operate similarly, certain features might not be available in both. In reality, you probably won't use most of makes extended features, but in a worst case scenario you might opt to maintain multiple Makefiles or limit yourself to a common subset of features.
At the end of the day, it all boils down to what your professor will want. Odds are 95+% that you can do 100% of the work in Linux, but the prof's requirements or grading environment might be such that you will have to copy your code into a UNIX account to build the final "submission" executable. Considering that university UNIX accounts aren't nearly as portable as Linux on a laptop, the cost of the "final verification / porting" to the University computer is likely to be small compared to the convenience of working on your homework more hours than you can manage in a fixed lab.

Resources