Hello. Perhaps a stupid post / question, but still .. At the university we were given tasks - to find the source codes of the utilities (in my case - df, Linux), to deal with their code and based on them to try to implement our own utility. I downloaded several different versions of the utility source, but none of them really want to compile with gcc, a billion libraries from coreutils stretch for it, and for some reason not all standard libraries (for example, system.h) are connected β€” they fail. A bunch of different "types" is unknown from what hiderov used in the texts of the utility .. In general - a continuous darkness. Can anybody explain to me what is wrong with these sources I am doing - why are they not compiled simply? And how could one realize the utility itself (hb part of its capabilities)? One of the versions of the source codes that I watched was http://lingrok.org/xref/coreutils/src/df.c#ncolumns

__ Concerning errors with libraries - tritely on the first lines the compiler swears at the standard library: df.c: 21: 20: fatal error: config.h: There is no such file or directory compilation is interrupted

  • one
    and readme read? Who will do ./configure && make ? - gecube
  • @gecube, I am a complete zero in Linux (to my regret, but what to do if such a task is given), but how should I write such a command completely? gcc -o df.out df.c && ./configurate && make? and if I don't have a makefile, what should I write in it? - alena_fox_spb
  • Makefile (it is written with a capital letter) can be generated by the configuration script. - KoVadim
  • By the way, if there are both (makefile and makefile), then make will execute the makefile (with a small letter). - avp
  • one
    @alena_fox_spb is not that you are a complete zero. You just need to google a little and figure out (preferably, of course, independently) how to build programs. It does not matter under Linux or Windows. In this case, how to build programs from the Makefile.am. ./configure && make needs to be done in one command β€” it config.h based on user responses and system scans for the presence of a compiler, its version and the presence and versions of libraries. And make starts the process of compiling source files. Well, if it is simple. Just gcc -o df.out df.c in this situation do not go - gecube

2 answers 2

1) Most of these utilities come in one package. It is impossible to compile separately in most cases. Rarely what utility comes as one .c file.

2) some utilities use their internal libraries. In the Linux kernel and environs, it is not customary for each utility to drag everything that is needed. The size of the sorts would be noticeably higher and much duplicated.

3)

fatal error: config.h:

since the utilities are written with the expectation that they will be compiled / run on a variety of systems, they are doing a β€œconfiguration” before compiling. A specially prepared script examines the environment and generates various data for compilation. usually a similar script generates a config.h file, where various constants are written.

4) Usually in Linux everything is compiled as

 ./configure # Π·Π°ΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ скрипт ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΈ make # Π·Π°ΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡ†ΠΈΡŽ make install # Ρ€Π°Π·Π»ΠΎΠΆΠΈΡ‚ΡŒ скомпилированноС Π΄ΠΎΠ±Ρ€ΠΎ ΠΏΠΎ мСстам. 

in some cases, there are ways and they are usually described in README files or the like.

  • Sorry for the continuation of "Stupid questions", but how do you spell (or rather, what to write) in the configuration script? - alena_fox_spb
  • The script for the configuration is the one who writes the program. And what exactly will be there - it depends on the program. - KoVadim
  • @alena_fox_spb - read about automake and alternatives - zb '

you need to learn the fstatfs (2) system call