Virtual machine with VirtualBox find and execute local C file - c

I am learning C at the moment and my university requires me to use a Virtual Maschine running Linux using VirtualBox. If I write a c program in my compiler (Codeblocks) on my Windows operating system, I do not know how I could execute the written C file.
At this website: https://www.howtogeek.com/189974/how-to-share-your-computers-files-with-a-virtual-machine/ I have seen that this can be done by "Insert Guest Additions CD image" and then adjusting "shared folders" in the settings.
Would this be the right approach? Can you give some examples of how I would then execute the code in the VM?
Thank you for your help!

First you need to compile it inside linux using clang or gcc because the windows version of codeblocks will compile it for windows, then the simplest solution is just cooy/paste the source code on linux or doing shared folders it is simple you go to the virtual box setting and install virtualbox guest additions and also install it inside the virtual machine, but what i would do is just do the whole thing in linux :)

The link you give shows how to share files between your native OS and the virtual machine. This is a perfectly acceptable way to transfer a file which is already in Windows. However, it would be much simpler to create the file in the VM in the first place. I suggest you learn how to use vim or emacs to edit your code files in Linux.

Related

Compile and execute C program in Python using Windows

I need to iteratively edit, recompile and run a C program called sum_subgiants.c through Python (using Spyder on Windows). I am using a python code that has previously worked on my colleague's Mac. I am a novice with python and have no experience with C.
There is a makefile and all relevant files stored in the same folder as sum_subgiants.c. I have tried
subprocess.run('make sum_subgiants', shell=True)
to compile and then
subprocess.call('sum_subgiants', stdin=input_file, stdout=output_fh, shell=True)
These commands do not appear to do anything. Any help in terms I can understand would be much appreciated.
I notice that there is no make command on Windows, which explains the error. Is there an alternative command that would work on Windows?
Should I expect subprocess.call to run easily after I have sorted out the make?
Since you are on Windows, everything is difficult.
You need to install a C compiler on the Windows machine.
You need to install make on the Windows machine.
Depending on what is done in the makefile, you might need to install other tools as well.
You could consider installing MSYS2 and MinGW, which provide a Unix-like environment for Windows.
But I would question the whole procedure: Why is it necessary to dynamically build a C program at run time? This is going to be so complicated that looking for an alternative solution might be preferable.

Can you code a shell for Linux using Windows OS and Dev-C++ IDE? Do shells work the same way for both operating systems?

I'm studying computer engineering and we have a class called operating systems where they lecture us about how OSes handle stuff etc. This week we were given a homework which requests us to code a shell that works on Linux. The problem is, they tought us literally nothing on how to code a shell so we are supposed to do some research and figure it out.
I found this guide online and it seemed perfect to me: link
Code, with explanations, what else could I ask for.
Now, I'm using a Windows PC and I use Dev-C++ IDE with GCC compiler. Can I code a shell that works on Linux with my current setup or do I have to install Linux? Are there any major differences between how shells run on these OSes?
If you want to write a shell for Linux, you want to target GNU/Linux which is basically POSIX with some extensions.
Dev-C++ by default uses MinGW GCC as its compiler, providing a Win32 API.
Win32 and POSIX are completely and fundamentally different. A shell written for one will not even slightly resemble the other.
Instead, you have several options:
Dev-C++ can optionally use Cygwin GCC, providing a more GNU/Linux-like experience on Windows. You need to take great care not to rely on any Cygwin-specific functionality like how it automatically translates pathnames and line terminators. You'll still need access to a Linux install to verify that it works.
Windows 10 lets you install WSL, a more modern Linux compatibility layer for Windows. Dev-C++ doesn't explicitly states it support it, so you may need to edit and compile separately, and may lose debugging functionality. You'll still need access to a Linux install to verify that it works.
Just run Linux in a VM. The only thing to care about is getting your shell working.
I would suggest saving yourself a ton of trouble right now and just download/install an Ubuntu image in VirtualBox.

Cross-platform program to read/write files

I'd like to provide a program, for example a Python script, that can be run on platforms including Linux, Mac, and Windows. I want the program to read the content of a few files in the directory, and create a new file in that directory based on the content. Specifically, I want the program to find file1.txt and file2.txt, and create a new file file3.txt which is a concatenation of the first two files.
I might provide a Python script to a Linux user, and the user can run
python script.py
However, Windows does not have Python. What other choices of programs do I have that will allow it to be run on these platforms, without the user having to install anything extra?
You could use C++, but then you'd have to compile for each platform, which is sometimes more work than you'd like.
Most systems have some form of Java installed already, which could work.
Python runs on Windows, Mac and Linux, the user would just need to install it.
I am not aware of anything that will run on all OSes without any extra work. However, Java may be a good choice as it is commonly installed. You could use C++ but you would have to compile it on each machine you would like it to work on (Windows, Mac, Linux) you would also have to make sure you don't use any library that does not transfer to the other OSes.

Compiling a GTK+ application for windows from linux

I'm new to linux and have been learning gtk+ the past couple of days, and was wondering how you would go about compiling an application to run on windows instead of linux (ubuntu). I found this while doing a quick search but my knowledge of linux is non-existent at the moment so not sure how to proceed with the tutorial. Are there any alternative methods to do this?.
I've only compiled on Windows and used Cygwin to test 'nix versions (before going right into a 'nix OS and compiling), but looks like this might get you started.
Compiling in other OS does not make sense while you can't disribute your binary without testing it on the target platform.
Then why not to compile on the same platform?

Mac C run in window

Is it possible to run compiled C and C++ Files on a mac without opening and running it in terminal?
E.G is there a separate GUI i can use for executing compiled c programs?
Have a look at Pashua.
Terminal IS a GUI; it provides you with access to the shell while you're still in the window system. I don't know what you'd want this other GUI to do that Terminal isn't doing for you. You would still need to provide the file path to this other program, which it would then load for execution, and it would still need to open standard input / standard output, etc.
If you have the source code, however, you can use an IDE. Eclipse works well for that, but there are plenty of others.
You can run/develop C/C++ programs in XCode on Mac OS X. From within XCode its cmd-B to build, cmd-enter to run. XCode is the Mac IDE which you can download or its comes as an optional install or your Mac OS install disks.
XCode also supports code completion - hit ESC.
Also see: Working comfortably in C using Eclipse

Resources