2017-04-03 38 views
0

我想爲我的類創建一個makefile,但看起來好像 makefile無法看到或找到我的類,儘管它們在相同的 文件夾中。Makefile找不到其他類(Java,Linux,Ubuntu)

它運行時,我運行javac但不是當我運行生成文件。

的Makefile

JAVAC=/usr/bin/javac 
dir=src/myrepo 

.SUFFIXES: .java .class 

.java.class: 

     $(JAVAC) -cp . $< 

default: $(dir)/*.class 

clean: 
     if [ -e $(dir)/*.java~ ] ; then rm $(dir)/*.java~; fi 
     mv $(dir)/*.class bin; fi 

目錄是Assignment/MakefileAssignment/src/myrepo(在myrepo所有類)

類是PrintIt.javaBinarySearchTree.javaBinaryTree.javaRecord.java(所有myrepo)

錯誤:

/usr/bin/javac -cp . src/myrepo/BinarySearchTree.java 
src/myrepo/BinarySearchTree.java:3: error: cannot find symbol 
public class BinarySearchTree extends BinaryTree { 
            ^
    symbol: class BinaryTree 
src/myrepo/BinarySearchTree.java:9: error: cannot find symbol 
     public void insert (Record d){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:16: error: cannot find symbol 
     public void insert (Record d, BinaryTreeNode<Record> node){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:16: error: cannot find symbol 
     public void insert (Record d, BinaryTreeNode<Record> node){ 
            ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:16: error: cannot find symbol 
     public void insert (Record d, BinaryTreeNode<Record> node){ 
                ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:30: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d){ 
              ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:30: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d){ 
      ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:30: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:37: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d, BinaryTreeNode<Record> node){ 
              ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:37: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d, BinaryTreeNode<Record> node){ 
                ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:37: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d, BinaryTreeNode<Record> node){ 
                    ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:37: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d, BinaryTreeNode<Record> node){ 
      ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:37: error: cannot find symbol 
     public BinaryTreeNode<Record> find (Record d, BinaryTreeNode<Record> node){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:47: error: cannot find symbol 
     public void delete (Record d){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:51: error: cannot find symbol 
     public BinaryTreeNode<Record> delete (Record d, BinaryTreeNode<Record> node){ 
              ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:51: error: cannot find symbol 
     public BinaryTreeNode<Record> delete (Record d, BinaryTreeNode<Record> node){ 
                 ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:51: error: cannot find symbol 
     public BinaryTreeNode<Record> delete (Record d, BinaryTreeNode<Record> node){ 
                     ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:51: error: cannot find symbol 
     public BinaryTreeNode<Record> delete (Record d, BinaryTreeNode<Record> node){ 
      ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:51: error: cannot find symbol 
     public BinaryTreeNode<Record> delete (Record d, BinaryTreeNode<Record> node){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:70: error: cannot find symbol 
     public BinaryTreeNode<Record> findMin (BinaryTreeNode<Record> node){ 
               ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:70: error: cannot find symbol 
     public BinaryTreeNode<Record> findMin (BinaryTreeNode<Record> node){ 
                  ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:70: error: cannot find symbol 
     public BinaryTreeNode<Record> findMin (BinaryTreeNode<Record> node){ 
      ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:70: error: cannot find symbol 
     public BinaryTreeNode<Record> findMin (BinaryTreeNode<Record> node){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:77: error: cannot find symbol 
     public BinaryTreeNode<Record> removeMin (BinaryTreeNode<Record> node){ 
               ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:77: error: cannot find symbol 
     public BinaryTreeNode<Record> removeMin (BinaryTreeNode<Record> node){ 
                   ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:77: error: cannot find symbol 
     public BinaryTreeNode<Record> removeMin (BinaryTreeNode<Record> node){ 
      ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:77: error: cannot find symbol 
     public BinaryTreeNode<Record> removeMin (BinaryTreeNode<Record> node){ 
          ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:10: error: cannot find symbol 
      if (root == null) 
       ^
    symbol: variable root 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:11: error: cannot find symbol 
       root = new BinaryTreeNode<Record> (d, null, null); 
       ^
    symbol: variable root 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:11: error: cannot find symbol 
       root = new BinaryTreeNode<Record> (d, null, null); 
         ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:11: error: cannot find symbol 
       root = new BinaryTreeNode<Record> (d, null, null); 
             ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:13: error: cannot find symbol 
       insert (d, root); 
         ^
    symbol: variable root 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:19: error: cannot find symbol 
        node.left = new BinaryTreeNode<Record> (d, null, null); 
            ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:19: error: cannot find symbol 
        node.left = new BinaryTreeNode<Record> (d, null, null); 
               ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:24: error: cannot find symbol 
         node.right = new BinaryTreeNode<Record> (d, null, null); 
             ^
    symbol: class BinaryTreeNode 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:24: error: cannot find symbol 
         node.right = new BinaryTreeNode<Record> (d, null, null); 
                 ^
    symbol: class Record 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:31: error: cannot find symbol 
      if (root == null) 
       ^
    symbol: variable root 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:34: error: cannot find symbol 
       return find (d, root); 
           ^
    symbol: variable root 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:48: error: cannot find symbol 
      root = delete (d, root); 
      ^
    symbol: variable root 
    location: class BinarySearchTree 
src/myrepo/BinarySearchTree.java:48: error: cannot find symbol 
      root = delete (d, root); 
          ^
    symbol: variable root 
    location: class BinarySearchTree 
40 errors 
Makefile:12: recipe for target 'src/myrepo/*.class' failed 
make: *** [src/myrepo/*.class] Error 1 
+0

嘗試「dir =/src/myrepo」。好像你缺少正斜槓。 – Naidu

+0

看來classpath是錯誤的。你使用當前目錄但不應該是「./src」?假設myrepo是一個包名。 – vanje

+0

您還應該考慮使用像Maven,Gradle或Ant這樣的Java特定構建工具。 Make和Java不是最好的朋友。 – vanje

回答

0

找到了解決辦法:

# Assignment 1 makefile 
# Hendri Vermeulen 
# 29 March 2017 

JAVAC=/usr/bin/javac 
dir=src/myrepo 

.SUFFIXES: .java .class 

.java.class: 
     $(JAVAC) -cp src/myrepo $< 

default: $(dir)/Record.class $(dir)/BinaryTree.class $(dir)/BinarySearchTree.cla 

clean: 
     if [ -e $(dir)/*.java~ ] ; then rm $(dir)/*.java~; fi 
     mv $(dir)/*.class bin; fi 

不得不添加 「-cp SRC/myrepo」 與編譯命令,我的類路徑的目錄。