Working on a Debian-based Linux distro (PopOS), I have a folder of files and a Makefile containing
MODULES=move score main draw setup
OBJECTS=$(MODULES:=.cmo)
TEST=test.byte
OCAMLBUILD=ocamlbuild -use-ocamlfind
MAIN=main.byte
# Recipes
default: build #first build (dependies) then run utop (command)
utop
build:
$(OCAMLBUILD) $(OBJECTS)
test:
$(OCAMLBUILD) -tag 'debug' $(TEST) && ./$(TEST)
play:
$(OCAMLBUILD) $(MAIN) && ./$(MAIN)
clean:
ocamlbuild -clean
When I call make build
it seems to work just fine, but the resulting .byte
files don't run. In the terminal they show up in red, which indicates that the computer is understanding them to be archive files rather than executables. When I try to run ./main.byte
it says the file cannot be found even though the file is listed in the directory.
Moreover, when I build this on a Mac it works just fine. It builds the program and runs it correctly.
Any thoughts about what this could be?
I'm not fully sure why this works on a Mac but not my Linux machine, but I did manage to play with this enough to get a solution. If I change the Makefile to be
MODULES=move score main draw setup
OBJECTS=$(MODULES:=.cmo)
TEST=test.byte
OCAMLBUILD=ocamlbuild -use-ocamlfind
MAIN=main.byte
default: build
utop
build:
$(OCAMLBUILD) $(OBJECTS) $(MAIN)
test:
$(OCAMLBUILD) -tag 'debug' $(TEST) && ./$(TEST)
play:
$(OCAMLBUILD) $(MAIN) && ./$(MAIN)
clean:
ocamlbuild -clean
then the computer recognizes the executable.
In your original Makefile, make build
does not run the command ocamlbuild $(MAIN)
which should create the bytecode executable. You have to run make play
for the bytecode executable to be built. In the modified Makefile, you included $(MAIN)
in the list of targets passed to ocamlbuild in your build
Makefile target, so now it is built by make build
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.