How does the make command automatically link to the cs50 library or the libraries used?
minh-cong opened this issue · 3 comments
minh-cong commented
I've been struggling with it all day and just found a way to create a makefile. But folders that do not contain makefile files will not automatically link to the cs50 library.
dmalan commented
arkadatavn commented
Thank you professor
goyalyashpal commented
just saving for myself:
- the
Makefile
itself can be made to essentially supply just the variables' definition tomake
, - i.e. like the https://cs50.readthedocs.io/libraries/cs50/c/#environment-variables section, but without actually dabbling in the mess that is the environment variables
--debug=why
is added in GNU make v4.4 (2022-10). Unfortunately cs50.dev is still using GNU make v4.3 (2020-01)
MAKEFLAGS += --debug=why
# MAKEFLAGS += --no-silent
# MAKEFLAGS += --warn-undefined-variables
CC := clang
CFLAGS := -std=c11
# Below are common C[XX]FLAGS
CCFLAGS += -ferror-limit=1 -gdwarf-4 -ggdb3 -O0
CCFLAGS += -Wall -Werror -Wextra
CCFLAGS += -Wno-gnu-folding-constant -Wno-sign-compare
CCFLAGS += -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable
CCFLAGS += -Wshadow
CFLAGS += $(CCFLAGS)
# LDLIBS := -lcrypt -lcs50 -lm
LDLIBS := -lm
# Following is for use with IDEs like Geany, Kate, Eclipse, IntelliJ, PyCharm, etc
.PHONY: all
all: # <pset_file_basename_i.e._without_extension>
# EXE = foo
# SRCS = foo.c bar.c
# OBJS = $(SRCS:.c=.o)
# $(EXE): $(OBJS)
# $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDLIBS)
# https://cs50.readthedocs.io/libraries/cs50/c/#makefile
# https://github.com/cs50/libcs50/issues/287
for using on windows, as these vars are essentially common to all the cs50x psets based on c-lang so, just cmd /c mklink /h Makefile <pset>\Makefile
(ref: howtogeek/win-symlink)
References:
-
Implicit Variables to make https://www.gnu.org/software/make/manual/make.html#Implicit-Variables
-
--debug=why
shows following output:$ make --debug=why inheritance <builtin>: update target 'inheritance' due to: inheritance.c
-
MAKEFLAGS
variable:declare mk="$(curl "https://www.gnu.org/software/make/manual/make.txt")"
then do:
tac - <<< "$mk" | grep flags -m7 -A4 | tac # ^~~~ A(fter) since `tac`ed
Or equivalently:
echo "$mk" | bat # then do: `?flags` and hope for it to wrap back and show search results from last