Muhammad Umar
Muhammad Umar

Reputation: 11782

Compile entire C project instead of few files

I have an entire library made in C. It has almost 10 folders with a lot of files.

I have created a filename.c file in root folder and trying to compile it in mac using gcc test.c -o test however its not including header files. Generally I have to add all the header files gcc test.c libaudio.c -o test

How can I compile entire project instead of just one file.

Upvotes: 3

Views: 3601

Answers (4)

Gem Taylor
Gem Taylor

Reputation: 5613

I definitely recommend the make approach as it is scalable.

If you really only have a couple of files, gcc will accept multiple .c files on the command line and link them all to generate one executable.

Upvotes: 0

Edwin Buck
Edwin Buck

Reputation: 70939

Use a Makefile. make the utility the reads the configuration within the Makefile will automate the running of the individual commands, such that you only need to name the item you wish to be rebuilt.

make myprogram

And make will use the dependency information stored in the Makefile's rules to determine what other elements are "out of date", rebuilding those and assembling them into myprogram.

This is a decent "first time" tutorial for "make".

Here is the full blown documentation for "make"

Once you master the concepts within make, you can then use other tools that make maintaining Makefiles either easier, more portable, or both.

Some tools that improve upon "make" include "cmake", "automake", "the autotools collection", "scons", "waf", "rake", "doit", "ninja", "tup", "redo", and "sake". There are more, and some are programming language specific, or limited to a particular enviornment.

The reason I recommend "make" over the others is because "make" is a baseline that will always be present, and the features in the other tools are often not understood or recognized to be needed until you get enough experience with "make".

Upvotes: 2

Jose
Jose

Reputation: 3460

Makefiles will solve your problem. You can create your own rules to clear the project (remove the generated files), build the project indicating where is your compiler (compile the source files located in some specific path, extension, etc), set the output path and so on, without typing a large compilation order.

https://www.gnu.org/software/make/manual/make.html

Edit: There you will be able to find how to add shared, static or raw libraries to your proyect through makefiles.

Upvotes: 4

rotoglup
rotoglup

Reputation: 5248

In C, the concept of project is not part of the language, it depends generally of the tools / platform / library you have to build.

On Linux based platforms, you may have a makefile describing the project, or the library may have a cmake script.

You should be able to find the build instructions in you library documentation.

Upvotes: 0

Related Questions