Page 1 of 2 12 LastLast
Results 1 to 20 of 37
  1. #1
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default Help with Linux Makefile

    Hello,

    This is a cross-post from the Java Sun forums..

    Jive Software

    The reason why I am posting here is because I am a bit pass the deadline and am still having trouble creating this makefile.. I am seeking additional help..

    Here is the situation..
    I used Netbeans on a Windows platform to create my program. Everything is finished and works perfectly, but my professor denied my submission of the assignment because he wants the program in a makefile. I have never worked with makefiles nor have I ever worked on Linux. I have been looking on google a lot and trying lots of different techniques to create makefiles but to no success. I have gone as far downloading on Linux the Java SDK and have learned to use Javac Main.java etc. etc.
    but that is as far as I go without going more into depth on how to compile multiple files at once. Would someone mind walking me through on how to create the necessary makefile?

    I have five classes: Main.java, Course.java, Rooms.java, CSVReader.java, CSVParser.java

    CSVParser.java and CSVReader.java are classes I pulled from the internet, it is an opensource CSV reader..

    I have put all of the .java files into the same directory, and have navigated through the terminal to the correct folder where all of these files are located.

    But I constantly keep receiving errors that either Rooms symbol cannot be found or Courses symbol cannot be found..

    One issue where I might be running into but I am not exactly sure.. is that I have in my Rooms class referenced to the Course class and the Course class has references to the Rooms class..

    Somebody please help!

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Rooms and Course referencing each other is fine. Make sure though that, if the classes are all in the same directory, the all have the same package name (or none at all)

  3. #3
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    Yep, they all have the same package..

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    so i assume when you hand-compile them everything works?

    copy-paste your makefile in here, and don't forget the [ code ] tags

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    When using packages be sure the classpath points to the folder where the package path starts.

  6. #6
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    Java Code:
    JFLAGS = -g
    JC = javac
    .SUFFIXES:	.java	.class
    .java.class:
    	$(JC)	$(JFLAGS)	$*.java
    CLASSES = \
    	Main.java\
    	CSVReader.java\
    	CSVParser.java\
    	Rooms.java \
    	Course.java 
    
    
    default: classes
    
    classes: $(CLASSES:.java=.class)
    
    
    
    clean: 
    	$(RM) *.class
    That is my makefile..
    This is my error.. (Sorry in advance if this is too long
    Java Code:
    )
    rob@rob-laptop:~/Desktop/attachments_2010_06_07/ClassSched/src/classsched$ makejavac	-g	Rooms.java
    Rooms.java:23: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> M = new ArrayList<Course>();
                     ^
    Rooms.java:24: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> T = new ArrayList<Course>();
                     ^
    Rooms.java:25: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> W = new ArrayList<Course>();
                     ^
    Rooms.java:26: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> H = new ArrayList<Course>();
                     ^
    Rooms.java:27: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> F = new ArrayList<Course>();
                     ^
    Rooms.java:28: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> S = new ArrayList<Course>();
                     ^
    Rooms.java:29: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> courseList = new ArrayList<Course>();
                     ^
    Rooms.java:43: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        public boolean hasTimeConflictWithCourse(Course e) {
                                                 ^
    Rooms.java:121: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        public boolean hasCourseduringDay(Course e) {
                                          ^
    Rooms.java:198: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        public void addCourse(Course e) {
                              ^
    Rooms.java:250: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        public Course getCourse(int i) {
               ^
    Rooms.java:23: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> M = new ArrayList<Course>();
                                               ^
    Rooms.java:24: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> T = new ArrayList<Course>();
                                               ^
    Rooms.java:25: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> W = new ArrayList<Course>();
                                               ^
    Rooms.java:26: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> H = new ArrayList<Course>();
                                               ^
    Rooms.java:27: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> F = new ArrayList<Course>();
                                               ^
    Rooms.java:28: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> S = new ArrayList<Course>();
                                               ^
    Rooms.java:29: cannot find symbol
    symbol  : class Course
    location: class classsched.Rooms
        private List<Course> courseList = new ArrayList<Course>();
                                                        ^
    18 errors
    make: *** [Rooms.class] Error 1

    Also, another thing I just realized is.. I use two csv files in my program.. which is also in the same directory.. but I just realized I did not reference it in my makefile.. perhaps I should? The files are called spring2010.csv and classrooms.csv
    And after executing the file, it is suppose to create a csv file called assignments.csv
    Am I suppose to make a reference to that also?
    Last edited by ruerric; 06-09-2010 at 04:45 AM.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    when you hand-compile them everything works?
    Are you able to compile the files manually? If you get the correct format for the javac command (including classpath) then you can put that in the make file.
    have the same package
    Does the classpath point to the start of the package path?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by ruerric View Post
    Hello,

    This is a cross-post from the Java Sun forums..

    Jive Software
    This made me grin...I think this is the first time I have encountered someone actually being polite enough to inform us they have asked this question elsewhere as well.

    :)

    I'm afraid I don't have an answer to your question, since I had the MAKE section of my brain surgically removed years ago...the horror...:eek:

  9. #9
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    I have yet to hand-compile the project.. The furthest I have gone was

    Javac Main.java Course.java etc etc..

    Do I have to include the .csv files in my compile?

  10. #10
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    no, you don have to include .csv

    Makefile is a shortcut to hand-compiling your stuff. You cant compile it, Make won't help, will just make things more difficult to figure out.

    do this:
    javac *.java

    and make sure that works.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Do I have to include the .csv files in my compile
    No, the compiler doesn't look at a program's data files.

  12. #12
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    i did javac *.java

    Results:
    Note: Main.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    And that is it.. no errors..

    any suggestions?
    Last edited by ruerric; 06-10-2010 at 02:57 AM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Next step after compiling and getting no errors is to execute it.
    What happens when you execute the program?

  14. #14
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    silly question, how do i execute it?

    Edit * - I typed Java Main.class and tried Java main

    No luck for either
    Last edited by ruerric; 06-10-2010 at 03:12 AM.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Wow! Some more magic of the IDEs uncovered.

    Use the java command to execute a java program. For example if FirstPgm.class has your main() method (no package) then enter:
    java FirstPgm

    That's on Windows, I don't know what paths might be required on linux.

  16. #16
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    i have tried that already.. Main.class is my main() method..
    I tried removing the "package classsched" in all of the .java files but now i can't compile them with an error saying it cant access one of my classes..

  17. #17
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    This is what the error code is.. if it helps

    Java Code:
    rob@rob-laptop:~/Desktop/attachments_2010_06_07/ClassSched/src/classsched$ javac Main.java Course.java Rooms.java CSVReader.java CSVParser.java
    Note: Main.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    rob@rob-laptop:~/Desktop/attachments_2010_06_07/ClassSched/src/classsched$ java main
    Exception in thread "main" java.lang.NoClassDefFoundError: main
    Caused by: java.lang.ClassNotFoundException: main
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: main.  Program will exit.
    rob@rob-laptop:~/Desktop/attachments_2010_06_07/ClassSched/src/classsched$
    I have uploaded my program in a .zip file.. I am now desperate to know why I can't create a makefile..
    http://rapidshare.com/files/39730841...Sched.zip.html
    Last edited by ruerric; 06-10-2010 at 06:56 AM.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Don't remove the package stuff.
    If they're packaged you need the full class name, which would be packagename.Main.
    so:
    java classsched.Main

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    make and javac don't work well together: make tries to update its dependencies one unit per step while javac compiles the whole shebang if needed *and* if it can find the necessary sources. When you hand-compile you're feeding all your sources to the compiler (javac *.java) and it compiles them all. When you're running make you're effectively feeding one source file to javac per step. Javac needs the other sources too but it can't find them so make signals the error and stops. Javac has a flag that specifies where it should search for other sources (if needed). Run javac as follows in your make script:

    Java Code:
    JFLAGS = -g -sourcepath /path/to/your/source/files
    That way javac finds the depending sources and compiles all the needed files. See what happens to the 'make-jobs' (not all are run by make because javac already compiled the sources).

    kind regards,

    Jos

  20. #20
    ruerric is offline Member
    Join Date
    May 2010
    Posts
    19
    Rep Power
    0

    Default

    Changed my JFAGS to:

    JFLAGS = -g -sourcepath ~/Desktop/attachments_2010_06_07/ClassSched/src/classsched

    Still no luck.. still getting the Cannot find class symbols.

Page 1 of 2 12 LastLast

Similar Threads

  1. Linux Shell
    By rp181 in forum Advanced Java
    Replies: 2
    Last Post: 01-30-2010, 05:51 AM
  2. MakeFile
    By divyanshu023 in forum New To Java
    Replies: 1
    Last Post: 09-18-2009, 09:16 AM
  3. Running Linux
    By selva.bics in forum AWT / Swing
    Replies: 1
    Last Post: 08-31-2009, 08:01 PM
  4. Replies: 6
    Last Post: 04-08-2009, 05:05 AM
  5. Help regarding makefile problem
    By rams in forum Networking
    Replies: 0
    Last Post: 11-17-2008, 04:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •