How to compile a Firmware project by using command prompt - c

I am looking for a bunch of code lines to compile a firmware project by using command prompt. I found for compiling just a .c file it's enough to write gcc -o filename.c.
However my project is a folder with a number of .c files .h files and 3 other formats and I have no idea how to run and compile the whole folder by cmd.
Here is content of project:
Would you give me some advice on what are related commands for this?
Thanks

Related

GCC <includes> multiple sub folders

I want to compile some C code with GCC but having problems with linking the necessary files.
I have a simple .c file that includes 3 header files from other repo projects that I have downloaded and put in my working folder. The -I command lets me add folders to the compilation but it fails on one of the repos because it seems like the command is not recursively looking through subfolders.
How do I tell the compiler that he has to look for includes in all subfolders of my current working directory ?

Equivalent of 'make' command for CodeBlocks?

I am using Codeblocks in Windows 10. Earlier I used to compile only 1 file, so I would just press the 'Build' and 'Run' button on codeblocks.
But, this time there are separate files I need to compile separately (to .o format) and then link to form a single executable file which I need to run. How can I do this in CODEBLOCKS? (In UNIX/LINUX systems, I know this is the 'make' command; but I don't know how to do it here?)
Can anyone help me? I tried reading some help pages on CodeBlocks on the internet, but they were so complicated, I gave up.
make isn't a compiler, and neither is CodeBlocks. make is just a command that runs other commands from a Makefile. The actual command that gets run is something along the lines of gcc a.cpp b.cpp, and it's the same command (or similar enough) that gets run when you build inside CodeBlocks. CodeBlocks should automatically build and link all of the source files that you add to your project. If you aren't seeing this happening, make sure you add them to the project inside of CodeBlocks and don't just put the files in the directory.

Export C library to Windows dll

So I have source code written in C for the LibIdn2 library. I am looking to port it into C# but running in to some issues along the way and would appreciate some help.
Installed Cygwin along with Make and GCC G++ packages
Successfully able to run the./configure command on the source directory
After this, running the "make" command produces an .exe file.
I have been trying to get a .dll file created but cannot seem to do so using gcc compiler. The command I am running is:
gcc -shared -o idn2.dll src/idn2.c
but it complains that it cant find the header files referenced in the idn2.c source file.
I have checked that in the idn2.h file, dll_Export is defined.
Any ideas how should I proceed? I need to get a dll.

Can we run a python script in make which generates a few .c and .h files and then build an image?

I have a json file from which I need to generate .c and .h files and then build my image.
Is there some way through which I can run a python script first and then build c files when developer runs Make?
In CMAKE, you can use add_custom_command this way, consult cmake documentation
add_custom_command(OUTPUT ${YOUR_OUTPUT_FILE} COMMAND your_generate_command --outputfile=${YOUR_OUTPUT_FILE} --inputfile=${YOUR_JSON_FILE} DEPENDS ${YOUR_JSON_FILE} VERBATIM)

.exe file is not being created in windows for C by cmd by gcc compiler

i am also worried about how to make u guys understand about my problem and share my experience. i am learning C.in previous, i used the Code-blocks IDE to compile and run C code.i learned that as a beginner it would better to use cmd to compile and run code than IDE. i am using windows 8. Before i was not use to with cmd, i also learned that to be a advance user and good programer i should know the use of cmd well.
After setting the environment variable started to compile c code by cmd by the following command
gcc -o "executable file name" "C source code file name"
it craete a .exe file. but no .o file. when i worked with IDE, also a .o file was found with .exe
what is the possible reason for it?
after compiling the code, i ran it by calling "executable file name".
and when checked the directory, then a .exe file was found.
but now the problem is, recently i am compiling and running code, i found that there is no .exe file created, but a file has created with unknown extension"POINTERWHILE File (.pointerWhile)"(copied from file properties). this unknown extension file is only runing by the cmd. it may be the one part of my source code file name. the code has given below and the name of source code.
Name of source code: Example184.1.pointerWhile
#include<stdio.h>
main()
{
char *p = "stop";
char str[80];
do
{
printf("Enter a String: ");
gets(str);
}
while(strcmp(p,str));
}
this program will take input until, "stop" entered.
this kind of things happened for several other files.then i copy them, to an another folder and compile and run but the same result.
i complied and run the same code form same folder and other folder by codeblocks, the result is same. the file is only running when it is in IDE.
then make an another file with other name in same directory and other, but the same code. then it is creating .exe file.
2.what may the cause for creating .exe file?
Great effort from you in learning the cmd along with C!
However, I think you're confusing the extension (name) of the file, and its contents. When you tell gcc to generate an executable file, you might want to give it a .exe extension, just like you said, assuming your source is called "myprog.c":
gcc -o myprog.exe myprog.c
This should always generate a myprog.exe file. But nothing prevents you from calling it like this:
gcc -o myprog.myFancyExtension myprog.c
You should still be able to run the program via the cmd (I didn't test that on windows though). Note that on other systems, like Linux, executable files usually have no extension at all.
Also, you're talking about how your IDE generates a myprog.o object file along with the myprog.exe executable file. To do this, your IDE is calling the compiler (gcc) twice: once to generate the .o file, and another time to generate the .exe file. There is no way to generate both files in one run of the compiler. The advantage of learning the cmd is that you will learn what your IDE is actually doing for you without telling you. The drawback is that you have to actually learn it ;)
Usually, people do not like to use gcc by hand, because as your projects grow, they will use different files and it becomes tedious to recompile them all manually. To overcome this, you will want to use a build tool, such as Make. I'm not familiar with development under Windows, so I can't recommend any specific tool. The point of those tools is that when your project has multiple source files, you only have to call the builder once, like this for Make:
make
instead of manually calling:
gcc -c myFeature1.c
gcc -c myOtherFeature.c
gcc -c myYetAnotherFeature.c
gcc -c myMain.c
gcc -o myMain.exe MyMain.o myFeature1.o myOtherFeature.o myYetAnotherFeature.o
Hope it helps

Resources