Build .c file in Window from Linux command.

1 view (last 30 days)
Hoai An Trinh
Hoai An Trinh on 31 Mar 2021
Edited: Rupesh on 29 Feb 2024
Dear everyone,
How can I convert the command: !make -f ert_main.c in Linux to the corresponding command in Windows?
Thank you so much!

Answers (1)

Rupesh
Rupesh on 23 Feb 2024
Edited: Rupesh on 29 Feb 2024
Hi Hoai An Trinh,
I understand that you are trying to compile a C program using a Makefile on a Windows system, where you would typically use the “make” command on Linux. The “!make -f ert_main.c” command you've mentioned might seem to have a typo; the -f flag is used to specify a Makefile, not a .c source file.
Consider a sample C file named check.c that you intend to compile. You will need to create a Makefile that provides instructions for the make utility on how to build your program. Below is one sample example for Makefile:
# Makefile
all:check
check: check.c
gcc -o check check.c
On Windows, you have a few options depending on the development tools you have installed:
1] Using MinGW or Cygwin
If you have MinGW or Cygwin installed, which provide a Unix-like environment on Windows, you can use the same make command in the MinGW or Cygwin terminal:
Make
2] Using nmake (Microsoft's make)
If you have Microsoft Visual Studio or the Windows SDK, you can use “nmake”. To compile using “nmake”, open a Visual Studio Developer Command Prompt or a command prompt where “cl” and “nmake” are in the PATH, navigate to the directory containing check.c and the Makefile, and run:
nmake
After the execution of the above commands from any of the ways you will get the following output.
In summary, to compile your C program on Windows, you will need to choose the appropriate tool based on what you have installed on your system. If you have a Makefile named ert_main.c, make sure to rename it to just Makefile or use the correct file name after the -f option when invoking “make” or “nmake”.
You can also refer to below documents on how one can build a C or C++ file in windows environment and on MATLAB setup.
Hope this helps!

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!