4 ms·
The compilers require a bunch of arcane flags to actually do something useful, so you pretty much need some kind of build system or at least a shell script.
by xigoi 2y ago
The compilers require a bunch of arcane flags to actually do something useful, so you pretty much need some kind of build system or at least a shell script.
- dmitrygr 2y ago> compilers require a bunch of arcane flags to actually do something useful $ gcc lolno.c && ./a.out lol, no $
- pitaj 2y agoNow do a project with multiple files.
- Calavar 2y agoThat still doesn't require any flags. Where it starts to get complicated is when you link in system libraries, because they vary between OSes and different versions/distros of the same OS. If you need to support multiple platforms this quickly becomes combinatorially complex, which is where Makefile hell comes from.
- spc476 2y agoSure. Here's viola, a web browser from the early 90s, with a replacement makefile (GNU make) that's a bit more sane: CC = gcc -std=c99 -Wall -Wextra -pedantic CFLAGS = -g LDFLAGS = -g LDLIBS = -L/usr/X11R6/lib -lICE -lSM -lXpm -lX11 -lXext -lXmu -lXt -lm VIOLA_PATH := $(shell pwd)/resources override CFLAGS += -DPOSIX_C_SOURCE=199309L \ -D_POSIX_SOURCE -D_XOPEN_SOURCE \ -D_BSD_SOURCE -D_SVID_SOURCE \ -DDEFAULT_VIOLA_PATH='"$(VIOLA_PATH)"'\ -DVIOLA %.a: $(AR) $(ARFLAGS) $@ $? viola/viola: $(patsubst %.c,%.o,$(wildcard viola/*.c)) \ libIMG/libIMG.a \ libXPA/src/libxpa.a \ libStyle/libStyle.a \ libWWW/libWWW.a \ parmcheck.o libIMG/libIMG.a : $(patsubst %.c,%.o,$(wildcard libIMG/*.c)) libXPA/src/libxpa.a : $(patsubst %.c,%.o,$(wildcard libXPA/src/*.c)) libStyle/libStyle.a : $(patsubst %.c,%.o,$(wildcard libStyle/*.c)) libWWW/libWWW.a : $(patsubst %.c,%.o,$(wildcard libWWW/*.c)) It's 155,000 lines of C code across 361 files. Not shown are the nearly 900 lines that make up the dependencies, but using `makedepend` (which came with my system) makes short work of that. I have a more complicated project that compiles an application written in Lua into a Linux executable. It wasn't hard to write, given that you can always add new rules to `make`, such as converting a `.lua` file to a `.o` file: %.o : %.lua $(BIN2C) $(B2CFLAGS) -o $*.l.c $< $(CC) $(CFLAGS) -c -o $@ $*.l.c $(RM) $*.l.c Okay, that requires a custom tool (`bin2c`) but can other build systems do this? I honestly don't know.
- Macha 2y agoGreat, now do TLS, a GUI, graphics rendering or database access.
- ryao 2y agoUse stunnel for TLS. A benefit is that if you properly sandbox the daemon behind it, a compromise in the daemon behind TLS does not result in the server key being compromised. A GUI could be done in SDL+Nuklear, GTK+ or others. Database access from C is easy, since the databases are written in C and provide C APIs for access.
- Dylan16807 2y agoCan you use those libraries without a bunch of arcane compiler flags? Because that's what the argument was about.
- ryao 2y agostunnel is not a library and linking to C libraries is easy.
- xigoi 2y agoWhy is the executable named ./a.out and not ./lolno? Why are warnings disabled by default? What if you need to use <math.h>? And that’s just for a single file.
- sudahtigabulan 2y ago> Why is the executable named ./a.out and not ./lolno? $ ls lolno.c $ make lolno cc lolno.c -o lolno $ ls lolno lolno.c
- gerdesj 2y agoI have been a Gentoo Linux aficionado for decades. When you set it up you define a set of CFLAGs and CXXFLAGS etc. Those are your globals, your defaults. I am also a human. When I deal with another person I have never met before, I have a set of defaults. I override them as required. gcc (at least) only requires an input and will behave reasonably and generate: a.out. You might like to pass -O2 for something a bit more complicated. Beyond that then yes you will need to get into details because any engineering discipline is tricksy!
- xigoi 2y ago> Beyond that then yes you will need to get into details because any engineering discipline is tricksy! When you have multiple files in your project or are using external libraries, pretty much any other programming language will know what tt do. Only C requires you to manually name them in the compilation command even though they’re already named in the file you’re compiling.