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.
Related
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.
I'm trying to get PortAudio to work on my computer. I've been using Cygwin and gcc to make applications in C, but I'm completely clueless as to how I might go about getting PortAudio to compile and work on my system.
I've found info on PortAudio's website for getting it to work with Microsoft Visual Studio, but I'm not using that IDE (or any for that matter. Just been working in Notepad++ and running things from the command line).
If anyone has any info for how I might get this to work, or where I might look for an answer, it would be much appreciated!
Thanks!
-Justin
You should be able to follow the PortAudio instructions for Linux.
As it says in the instructions, "You might need to use yum, or some other package manager, instead of apt-get on your machine". In the case of Cygwin, that probably means using the Cygwin setup.exe program.
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.
I am unsure about compiling C files into executables by using Cygwin under Windows 7.
Can anyone please tell me how to do this?
I've read some tutorials but still don't get it. I understand that I need a Makefile, but what shall I write into it to have an executable file after the compilation process?
For the beginning I would say it is enough to Install MinGW. If you have installed it you find in the bin folder a gcc.exe which is the Compiler. Either set the PATH Variable to the bin folder or go directly to this folder.
In terminal use:
gcc your_C_file.c
The output will be an exe.
There are several ways to compile c-files. Makefiles are just one possibility. But as you proposed it... Here are two tutorials for Makefiles:
http://makepp.sourceforge.net/1.19/makepp_tutorial.html
http://mrbook.org/tutorials/make/ (Content from 2012 accessable via waybackmachine)
But note, that you will also need a compiler (installed under cygwin).
Another possibility is to use Dev-C++, a IDE (Integrated Developement Environment) for C++. Once installed you can create a project and add your source code, and just compile the project. It also contains a c++ compiler (also supports C), which is named mingw. The makefile needed is automatically generated. So that's simpler for beginners.
You can download Dev-Cpp here: http://www.bloodshed.net/devcpp.html
Note: As you spoke about cygwin I assume you use Windows. Dev++ works only under windows, and you wont need cygwin.
Q: How can i compile c-files into an executable (.exe) file?
A: Get and use a C compiler.
GCC/Cygwin is one possibility. MS Visual Studio is another: you can download the free "MSVS Express" here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express.
How you interact with the compiler is another question.
You can certainly use a command line.
You can use a command line with or without "Make": you can let "Makefiles" do the "heavy lifting" for you, you can use .bat files, or you can type everything by hand.
Using a graphical IDE is another possibility. "Eclipse" and "MS Visual Studio" are two popular alternatives for Windows.
Even easier solution is A86 Assembler. Its old school but works perfectly, in the right hands ;)
There is few files with .c anf .h extensions (cmdline.c cmdline.h core.c core.h and so on) in src directory, also there is one file "MakeFile" without extension. Is there any possibility to build these source files into some executable file on Windows 7 (64bits) ? I think i need to download compilers for C or some sdks right?
Yes.
You need to:
download and install a C/C++ compiler (I recommend TDragon's distribution of MinGW ),
add the compiler to your PATH (the installer can do it for you most of the cases); verify it's done by opening cmd.exe and typing gcc -v and mingw32-make -v, both should give you half a screenful of version information if your path is set correctly,
via cmd.exe, navigate to the folder in which the Makefile resides and call mingw32-make.
From now on everything should compile automatically. If it doesn't, post the errors.
Update:
First of all, it'd be useful for you to get the MSys package. Install it and you'll have a more recent version of make (use it instead of mingw32-make from now on).
About the CreateProcess bug, it has to do with the system PATH variable being too long. You'd need to do something like this:
open cmd
execute set PATH=c:/mingw32/bin;c:/msys/1.0/bin (change the paths here to reflect your own installation if it's different)
then as before: navigate to your project's directory, run make. Everything should be smooth now if you're not missing any external libraries.
BTW- remember not to install MinGW or MSys in directories with spaces.
I am not a Windows Developer..
But still as per my knowledge. Visual Studio (i.e 2008, I guess) has the ability to read the Makefile.
Please have a look at it..and if needed change this makefile to their format..
There are many opensource product which are platform independent..and they get compiled on both OS with the just Makefile they provided.
Or else use 'cygwin'
Developer C++ works in windows but it is actually GCC code bought into Windows, Is anyone familiar about the procedure they used to convert the linux ( .sh) to executables ??
I think i need to download compilers for C or some sdks right?
A compiler certainly, but what additional libraries you may need will depend entirely on the code itself. A successful build may also depend on the intended target of the original code and makefile. The makefile may be a GNU makefile, but there are other similar but incompatible make utilities such as Borland Make and MS NMake. If it is a simple build, you may be able to avoid the makefile issue altogether and use the project management provided by an IDE such as Visual C++ 2010 Express.
If you do not know what this code is or what it does and what it needs to build, you are taking a risk building it at all. Maybe you should post a link to the original source so that you can get more specific advice on how to build it.
[EDIT]
Ok, now looking at the code you are attempting to build, it is a very simple build, so if you wanted to avoid using GNU make, then you could just add all the *.c files in the src folder to a project in your IDE and build it.
However there is one serious gotcha, it uses the BSD sockets API and Linux system headers. You will need to first port the code to Windows APIs such as WinSock (very similar to BSD Sockets), or build it under Cygwin (a sledgehammer for a nut somewhat). There may be other Linux dependencies that need sorting, I have not looked in detail, but it looks fairly simple. That said, if you did not have the first clue regarding compiling this stuff, then perhaps this is not a task you could do?
Of course compiling the code may only be half teh problem, if it was designed to run on Linux, there may be run-time dependencies that prevent it running on Windows. Again I have not looked in detail.
Also looking at the code, I would suggest some caution, this may not be the best quality code. That may be unfair, but one obvious flaw and an indication if inexperience is the lack of include guards in the headers.