[英]“error: cannot find symbol” when compiling with javac using makefile
My directory currently looks like this我的目录目前看起来像这样
├── Makefile
├── run_tests (Unix executable)
└── src
└── vehicles
├── Wheels.java
└── Cars.java
└── RunProgram.java
tests
└── test1.txt
└── test2.txt
RunProgram.java is my main. RunProgram.java 是我的主要工作。
Looking online, I currently have a Makefile that looks like this:在网上看,我目前有一个Makefile,看起来是这样的:
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
src/vehicles/Wheels.java \
src/vehicles/Cars.java \
src/RunProgram.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
I have two main issues right now.我现在有两个主要问题。
1. Cars.java throws an "error: cannot find symbol" for Wheels even though it compiles Wheels first (previously I had the order wrong, now it's correct). 1. Cars.java 为 Wheels 抛出“错误:找不到符号”,即使它先编译 Wheels(之前我的顺序错误,现在它是正确的)。
2. I'm going to need to add a "test" to the Makefile eventually, which comes with its own problems. 2.我最终需要在 Makefile 中添加一个“测试”,这有其自身的问题。 Essentially run_tests will put everything in the tests folder through System.in.
本质上,run_tests 将通过 System.in 将所有内容放在测试文件夹中。 However it has trouble running things in another directory, so I have to output the RunProgram.class to the root directory.
但是它在另一个目录中运行东西有问题,所以我必须将 output RunProgram.class 到根目录。
THIS IS HOW I RAN THE TESTS FROM THE COMMAND LINE WHEN THE ONLY PROGRAM IN THE PACKAGE STRUCTURE WAS RunProgram.java当 PACKAGE 结构中的唯一程序是 RunProgram.java 时,这就是我从命令行运行测试的方式
javac -d ./ ./src/RunProgram.java
./run_tests "java RunProgram"
However, when I try running javac now I get errors that package imports don't exist.但是,当我现在尝试运行 javac 时,我收到 package 导入不存在的错误。 This is why I'm going with Makefile, as that's the ideal solution.
这就是我选择 Makefile 的原因,因为这是理想的解决方案。
TL;DR I need a way to compile my program with Makefile and write a "make test" command that can properly call run_tests TL;DR我需要一种方法来用 Makefile 编译我的程序并编写一个可以正确调用 run_tests 的“make test”命令
I'm also willing to accept a solution that allows me to run javac from the command line and run the the tests from there, but Makefile is preferred我也愿意接受允许我从命令行运行 javac 并从那里运行测试的解决方案,但首选 Makefile
Best I could do to solve this was make a jar file and then do ./run_tests "java -jar RunProgram.jar"
Obviously not ideal but it worked.我能做的最好的解决方法是制作一个 jar 文件,然后执行
./run_tests "java -jar RunProgram.jar"
显然不理想,但它确实有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.