Thread: Homework Problem help!! Please.

  1. #1
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108

    Homework Problem help!! Please.

    I have a two programs: one is called taxes.cpp and the other is called assign2c.cpp. I've written them to the specifications of the design plan.

    I write the makefile to link both the programs together, but it doesn't seem to be working.

    Code:
    main: assign2c.cpp taxes.o
          g++ assign2c.cpp taxes.o -o main.exe
    taxes.o: taxes.cpp 
          g++ -c taxes.cpp -o taxes.o -c
    The code taxes is supposed to spill out Federal tax and State Tax, SSI tax which the variables that i have set up for them are already in the code of assign2c.cpp.

    Thank you!
    Last edited by arti; 03-22-2013 at 06:14 AM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by arti View Post
    I have a two programs: one is called taxes.cpp and the other is called assign2c.cpp. I've written them to the specifications of the design plan.

    I write the makefile to link both the programs together, but it doesn't seem to be working.

    [:code]
    main: assign2c.cpp taxes.o
    g++ assign2c.cpp taxes.o -o main.exe
    taxes.o: taxes.cpp
    g++ -c taxes.cpp -o taxes.o -c
    [:/code]

    The code taxes is supposed to spill out Federal tax and State Tax, which are already in the code assignment2c.cpp.
    What am I doing wrong in the makefile?

    Thank you!
    You need the post the makefile using codetags in a correct fashion.
    Are you using a real text editor to create the makefile?

    Does anything get built by the makefile?

    What command did you use to run the makefile?

    Do you know the difference tabs and spaces play in a makefile?

    I used 6 leading spaces in posting below instead of a tab as needed in a makefile.
    Code:
    main: assign2c.cpp taxes.o
          g++ assign2c.cpp taxes.o -o main.exe
    
    taxes.o: taxes.cpp
          g++ -c taxes.cpp -o taxes.o -c
    Tim S.
    Last edited by stahta01; 03-22-2013 at 06:21 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    I don't think anything got built by the makefile.
    even though when I type 'make' on the command line it gives me
    Code:
    g++ -c taxes.cpp -o taxes.o -c
    g++ assign2c.cpp taxes.o -o main.exe
    Yes I know the difference it plays. I only spaced when i needed to and tabbed once.
    i also edited the post to put the correct tags. Thank you for telling me though.
    Also, I'm using the terminal that Ubuntu has.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    g++ -c taxes.cpp -o taxes.o -c
    I suggest removing the final "-c" option.
    Unlikely to fix anything; but, it should not be there.

    If you type the commands (output by the make command) on the command line do they work?

    Edit: I suggest using the command "make main" instead of just "make".

    Tim S.
    Last edited by stahta01; 03-22-2013 at 06:29 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Yes the commands when i type them in work. At your suggestion I removed the -c option. Thank you for telling me about that. i was told differently by the tutor at school :/

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Did you try doing "make main" twice in a row if it was built the first time it should say some about it the second time.

    And, I need the exact command you are using to call the makefile because the -n option does exactly what you saying is happening.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    This is the makefile I would use.

    And then call it by "make all".
    Remember to replace the leading spaces with a single tab for each command to be executed.

    Tim S.

    Code:
    clean:
          rm -f main.exe
          rm -f taxes.o
    
    all: main.exe
    
    main.exe: assign2c.cpp taxes.o
          g++ assign2c.cpp taxes.o -o main.exe
     
    taxes.o: taxes.cpp
          g++ -c taxes.cpp -o taxes.o -c
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Doing "make taxes.o" results in what output?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Okay, thank you! I wrote and I will respond shortly to tell you if it worked.

  10. #10
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    By typing make taxes.o the output is
    Code:
    g++ -c  taxes.cpp -o taxes.o -c

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Someone appears to have alias "make" to "make -n".
    I have no memory how to unalias commands in Linux; been too long.
    http://www.mediacollege.com/linux/command/alias.html

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with C homework problem
    By asexynerd in forum C Programming
    Replies: 18
    Last Post: 11-24-2012, 04:16 PM
  2. Problem with homework
    By somniferium in forum C Programming
    Replies: 21
    Last Post: 10-15-2011, 12:09 PM
  3. homework problem Please Help!
    By alexwink in forum C Programming
    Replies: 24
    Last Post: 10-27-2006, 08:20 AM
  4. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  5. Need help please with a homework problem
    By AxlRose in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2004, 01:25 PM