Could you tell me how to achieve selective compilation?

now there is a C project. Suppose there are only main.c and pattern.h files, in which some standardized interfaces are defined

wants to achieve a function: provide the interface defined in pattern.h to user development, and eventually there will be a lot of c files containing the header file.

for example, classmate A writes a patternA.c to implement this interface,

classmate B writes a patternB.c to implement this interface,

both c files have -sharpinclude "pattern.h" and will exist in the same file directory at the same time.

finally in main.c or makefile , how do I choose one of them to compile the link?

for example, modify the macro definition in main.c or run make patternA or make patternB

is best implemented through the latter, which avoids the need for users to modify the source code during compilation

May.26,2022

Makefile example

all: patternA patternB

patternA: main.c patternA.c pattern.h
    gcc -o $@ $^

patternB: main.c patternB.c pattern.h
    gcc -o $@ $^    

then

  1. make or make all compile patternA and patternB at the same time
  2. make patternA compile patternA
  3. make patternB compile patternB
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e35c3e-43ba6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e35c3e-43ba6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?