codejam.tk
codejam.tk

Reputation: 73

How are github project compiled & arranged mainly C project on Github

I am learning C programming language. To understand clearly how big projects are written in C. I browsed few Trending C projects on Github. This is project written in C: Here. One thing i don't understand is why there are so many folder in the project directory: bin, conf, contrib, docs, images, m4, man, notes, etc. The only folders i understand is src folder, which has all the header files and c files. But there is still one more doubt related to source folder. Every header file has a C file with same name. I can compile main file but how are main.c file linked to other C files. I guess the other C files has all the function defintions & main file is calling them. main.c has called header file which has all the fucntion prototypes. I am now little bit confused b/w these big projects management. Please help me to understand. Also where to read about it so i can learn this stuff.

What actually i want to ask is: If I have 5 files

main.c , header.h , function1.c, function2.c, fuction3.c. How can i use 3 functions written in these 3 function1,2,3.c files.

I want to learn how to built a big project and manage that in different files and the way files are arranged on GIT. Even if i create a project i'll write 1000 lines in same .c file which is a total mess. I want to learn how to manage this clearity and arrangement of projects. Where to learn all this?

Upvotes: 1

Views: 737

Answers (2)

One thing i don't understand is why there are so many folder in the project directory: bin, conf, contrib, docs, images, m4, man, notes, etc.

Because a piece of software does not only consist of source code. A lot of supplementary stuff is required:

  • the documentation (in /man and docs);
  • build scripts (usually for the de facto standard Unix configuration tools "autoconf", "automake", "M4" and "make", located in the conf and/or m4 folder);
  • resources that are used by the GUI if the program has one (/images);
  • etc.

I can compile main file but how are main.c file linked to other C files

Using a piece of software called the linker. A lot of compilers (including the popular GCC and Clang toolchains) invoke the system linker by default (unless you tell them that they should only compile but not link) which in turn resolves the references between the source files and creates the final executable. Read more about the C compilation process here.

I want to learn how to built a big project and manage that in different files and the way files are arranged on GIT. Where to learn all this?

Unfortunately, there's no single place you can gather all the wisdom from. You will need to use Google a lot, read the documentation and manuals and tutorials for build systems like make and version control systems like Git, etc.

However, I've found for you a relevant Stack Overflow question that should help get you started: How to split a C program into multiple files?

Upvotes: 3

4rlekin
4rlekin

Reputation: 758

I will put my two cents here.

About this source files:
As You probably already know there are header files (.h) which contains function declarations, you need to #include such file to be able to use functions from within, BUT if you take a peek inside one of such header files you'll notice that there are ONLY declarations, without definitions.
The .c files solves this mystery:
If you have file function.c with some functions inside and want use this functions in, say, main.c file you need to create header file for that: function.h which will contain declaration (prototypes) of that functions from function.c file. You also need to #include this header in function.c file if i recall correctly. Then you can #include such header to your main.c file and use this functions.

About code organization:
There are some best practices and methods for organization of code and project managements. Also sometimes IDE used by developer has some particular way of organizing projects.
Just for clarification: git itself doesn't enforce any particular organization

Upvotes: 1

Related Questions