#1
  1. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    42
    Rep Power
    0

    makefile - two executables


    i'm trying to create a makefile which will give two executables, but i'm having some problems. this is my makefile

    Code:
    CCC = g++  
    EXEC1 = HEncode
    EXEC2 = HDecode
    OBJ1  = main.o HEncode.o Tree.o Node.o
    OBJ2  = main.o HDecode.o Tree.o Node.o
    
    all:      $(EXEC1) $(EXEC2)
    
    $(EXEC1): $(OBJ1)
    	$(CCC) $(OBJ1) -o $(EXEC1)
    
    $(EXEC2): $(OBJ2)
    	$(CCC) $(OBJ2) -o $(EXEC2)
    
    main.o: main.cc
    HEncode.o: HEncode.cc HEncode.h
    HDecode.o: HDecode.cc HDecode.h
    Tree.o: Tree.cc Tree.h
    Node.o: Node.cc Node.h
    which gives me the following error:

    Code:
    g++   main.o HEncode.o Tree.o Node.o -o HEncode
    Undefined                       first referenced
     symbol                             in file
    HDecode::decode(void)               main.o
    HDecode::~HDecode(void)             main.o
    HDecode::HDecode(basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >)main.o
    ld: fatal: Symbol referencing errors. No output written to HEncode
    collect2: ld returned 1 exit status
    make: *** [HEncode] Error 1
    but if I change the all target line to:
    all: $(EXEC2) $(EXEC1)

    I get

    Code:
    g++    -c -o HDecode.o HDecode.cc
    g++   main.o HDecode.o Tree.o Node.o -o HDecode
    Undefined                       first referenced
     symbol                             in file
    HEncode::encode(void)               main.o
    HEncode::~HEncode(void)             main.o
    HEncode::HEncode(basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >)main.o
    ld: fatal: Symbol referencing errors. No output written to HDecode
    collect2: ld returned 1 exit status
    make: *** [HDecode] Error 1
    So I know it's a problem with my makefile.. besides, all the classes are pretty much empty..
    so how do I create a makefile which will give two executables?

    thanks for any help!! :)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    34
    Rep Power
    13
    You'll want to create a Make target that calls two other targets.


    The 2 targets will be the ones that create your two executables.
  4. #3
  5. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    42
    Rep Power
    0
    I did that

    all: $(EXEC1) $(EXEC2)


    all calls the two targets, but I'm still getting errors
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    4
    Rep Power
    0
    Are you sure the make file is the problem?

    I think you may be telling the Makefile to do the wrong thing.

    if you type

    "g++ main.o HEncode.o Tree.o Node.o -o HEncode" on
    command line do you get same error as if Makefile were used
    to issue this command?

    I'd guess you either don't have these functions defined that
    g++ is griping about, or you need to pass some other option
    to g++ to let it know where to find some kind of template.

IMN logo majestic logo threadwatch logo seochat tools logo