public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* undefined references
@ 2004-04-27 11:43 gnuml
  2004-04-27 12:16 ` Eljay Love-Jensen
  0 siblings, 1 reply; 29+ messages in thread
From: gnuml @ 2004-04-27 11:43 UTC (permalink / raw)
  To: gcc-help

Hi,

I am trying to compile some C++ code and link it to a couple of C++
libraries (Informix c++ libs). However, I get 'undefined references' for every
object from the libraries I use. The code compiles fine though.
Could anybody give me some suggestions on how to test the libraries/what
to be aware of when linking/what might cause the problem?
I'm using gcc 3.3.1 and all librarie are in place & specified in the
makefile.
Thanks alot!

Martin

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: undefined references
  2004-04-27 11:43 undefined references gnuml
@ 2004-04-27 12:16 ` Eljay Love-Jensen
  0 siblings, 0 replies; 29+ messages in thread
From: Eljay Love-Jensen @ 2004-04-27 12:16 UTC (permalink / raw)
  To: gnuml, gcc-help

Hi Martin,

It sounds like you need to recompile your Informix C++ libraries with GCC 
3.3.1.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 16:01                                     ` Tom Browder
@ 2007-12-02  2:59                                       ` Tom Browder
  0 siblings, 0 replies; 29+ messages in thread
From: Tom Browder @ 2007-12-02  2:59 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

Well?  What luck?

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:43                               ` Tom Browder
  2007-12-01 15:44                                 ` Tom Browder
@ 2007-12-01 17:45                                 ` Ted Byers
  1 sibling, 0 replies; 29+ messages in thread
From: Ted Byers @ 2007-12-01 17:45 UTC (permalink / raw)
  To: Tom Browder, Michael Sullivan; +Cc: gcc-help


--- Tom Browder <tom.browder@gmail.com> wrote:

> On Dec 1, 2007 9:34 AM, Michael Sullivan
> <michael@espersunited.com> wrote:
> ...
> > The virtual destructor is there because g++ was
> giving me a warning
> > about setCurrentSprite(int), which will be
> implemented in classes Ally
> > and Enemy - both descended from Character.  I've
> commented out the
> > virtual destructor in character.h and used your
> Makefile with the
> > following output:
> 
> Then problem is Character needs to have the virtual
> function defined,
> even if it does nothing.  So:
> 

This is true only if the class is not abstract, but
then there is something wrong with the design if there
is to be a noop function.  If it can properly be used
as an abstract base class, then declare the virtual
function in question to be a pure virtual function, as
in:

  virtual void foo(int) = 0;

But this will introduce compile time errors if there
is an attempt to instantiate it, in which case a
choice is to be made as to whether or not the class
can function as an abstract base class.  If it should
not be abstract, then something is wrong with the
design if there is a function that is merely a no-op
stub.  If it should be abstract, then the calling code
that tries to intantiate it is broken.

The practice of making the destructor virtual is a
good one, especially since the OP expressed the intent
of deriving a number of classes from the class in
question.

Ted

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:49                                   ` Michael Sullivan
@ 2007-12-01 16:01                                     ` Tom Browder
  2007-12-02  2:59                                       ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 16:01 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 9:49 AM, Michael Sullivan <michael@espersunited.com> wrote:
...
> Is this right?
...
> because when I make, I still get errors...
...
> battle.o: In function `battle::battle()':
> battle.cpp:(.text+0x9e3): undefined reference to

Right--undefined.  I forgot I've been messing with your code and had
defined the Character() constructor.

I'm not sure about all the rules, but I think you have several
choices.  Since you declared the default constructor, you must define
it.  If you don't declare it, it will be provided automatically  and
that may not be what you want.  Choices:

+ don't declare it

+ declare it private, don't define it

//header:
   private:
   Character();

+ declare it public, define it as noop

//header:
   public:
   Character(){}

+ declare it public, define it with actions

//header:
   public:
   Character();

//cpp

Character::Character()
{
  name[0] = 0;
  maxHP = 0;
  maxMP = 0;

  currentHP = 0;
  currentMP = 0;
}

The latter is what I did.  Ideally you can clean up your constructors
by organizing member variables and using initializer syntax, etc.

Other improvements for modern code include using STL strings, etc.  I
highly recommend Scott Meyers' books--much food for though.

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:44                                 ` Tom Browder
@ 2007-12-01 15:49                                   ` Michael Sullivan
  2007-12-01 16:01                                     ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 15:49 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help


On Sat, 2007-12-01 at 09:44 -0600, Tom Browder wrote:
> On Dec 1, 2007 9:42 AM, Tom Browder <tom.browder@gmail.com> wrote:
> ...
> >   define the virtual function:
> >
> >  virtual void setCurrentSprite(int){} // not '{}' and not ';'
> 
> That should have been:
> 
>   virtual void setCurrentSprite(int){} // note '{}' and not ';'
> 
> -Tom

Is this right?

michael@camille ourrpg $ grep virtual character.h
      virtual ~Character() {}
      virtual void setCurrentSprite(int) {}

because when I make, I still get errors...
michael@camille ourrpg $ make clean
rm *.o *~ core* battle
rm: cannot remove `core*': No such file or directory
rm: cannot remove `battle': No such file or directory
make: [clean] Error 1 (ignored)
michael@camille ourrpg $ make
g++ -W -Wall -pedantic `sdl-config --cflags` -c battle.cpp
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
g++ -W -Wall -pedantic `sdl-config --cflags` -c character.cpp
g++ -o battle battle.o character.o `sdl-config --libs` -lSDL_image
-lSDL_gfx -lSDL_ttf
battle.o: In function `battle::battle()':
battle.cpp:(.text+0x9e3): undefined reference to
`Character::Character()'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xf1b): undefined reference to
`Character::Character()'
collect2: ld returned 1 exit status
make: *** [battle] Error 1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:43                               ` Tom Browder
@ 2007-12-01 15:44                                 ` Tom Browder
  2007-12-01 15:49                                   ` Michael Sullivan
  2007-12-01 17:45                                 ` Ted Byers
  1 sibling, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 15:44 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 9:42 AM, Tom Browder <tom.browder@gmail.com> wrote:
...
>   define the virtual function:
>
>  virtual void setCurrentSprite(int){} // not '{}' and not ';'

That should have been:

  virtual void setCurrentSprite(int){} // note '{}' and not ';'

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:34                             ` Michael Sullivan
@ 2007-12-01 15:43                               ` Tom Browder
  2007-12-01 15:44                                 ` Tom Browder
  2007-12-01 17:45                                 ` Ted Byers
  0 siblings, 2 replies; 29+ messages in thread
From: Tom Browder @ 2007-12-01 15:43 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 9:34 AM, Michael Sullivan <michael@espersunited.com> wrote:
...
> The virtual destructor is there because g++ was giving me a warning
> about setCurrentSprite(int), which will be implemented in classes Ally
> and Enemy - both descended from Character.  I've commented out the
> virtual destructor in character.h and used your Makefile with the
> following output:

Then problem is Character needs to have the virtual function defined,
even if it does nothing.  So:

  make the destructor virtual:

  virtual ~Character(){}

  define the virtual function:

 virtual void setCurrentSprite(int){} // not '{}' and not ';'

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:27                           ` Tom Browder
@ 2007-12-01 15:34                             ` Michael Sullivan
  2007-12-01 15:43                               ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 15:34 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help


On Sat, 2007-12-01 at 09:26 -0600, Tom Browder wrote:
> You're getting the errors about vtable... because you have an
> undefined virtual function declared in character.h.
> 
> Getting rid of the virtual attribute eliminates those errors and
> allows a successful build (and you can eliminate the virtual
> destructor).
> 
The virtual destructor is there because g++ was giving me a warning
about setCurrentSprite(int), which will be implemented in classes Ally
and Enemy - both descended from Character.  I've commented out the
virtual destructor in character.h and used your Makefile with the
following output:

michael@camille ourrpg $ make
g++ -W -Wall -pedantic `sdl-config --cflags` -c battle.cpp
character.h:8: warning: 'class Character' has virtual functions but
non-virtual destructor
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
g++ -W -Wall -pedantic `sdl-config --cflags` -c character.cpp
character.h:8: warning: 'class Character' has virtual functions but
non-virtual destructor
g++ -o battle battle.o character.o `sdl-config --libs` -lSDL_image
-lSDL_gfx -lSDL_ttf
battle.o: In function `battle::battle()':
battle.cpp:(.text+0x84b): undefined reference to
`Character::Character()'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xc37): undefined reference to
`Character::Character()'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0xdb): undefined reference to `vtable for
Character'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0x12d): undefined reference to `vtable for
Character'
collect2: ld returned 1 exit status
make: *** [battle] Error 1

> Then you can concentrate on other problems in the overall program, if any.
> 
> I've attached a little cleaner Makefile for your consideration.
> 
> -Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 15:14 Undefined References J.C. Pizarro
@ 2007-12-01 15:30 ` Tom Browder
  0 siblings, 0 replies; 29+ messages in thread
From: Tom Browder @ 2007-12-01 15:30 UTC (permalink / raw)
  To: J.C. Pizarro; +Cc: gcc-help

On Dec 1, 2007 9:14 AM, J.C. Pizarro <jcpiza@gmail.com> wrote:
>
...
> Why doesn't it publish the parts of source code character.cpp and
> battle.cpp related with their uses and definitions?
>
> Is it well written the Character() constructor?
>
> Are there headers?

See the original message in this thread--it has a link to all Michael's code.

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 14:45                         ` Tom Browder
@ 2007-12-01 15:27                           ` Tom Browder
  2007-12-01 15:34                             ` Michael Sullivan
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 15:27 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 401 bytes --]

You're getting the errors about vtable... because you have an
undefined virtual function declared in character.h.

Getting rid of the virtual attribute eliminates those errors and
allows a successful build (and you can eliminate the virtual
destructor).

Then you can concentrate on other problems in the overall program, if any.

I've attached a little cleaner Makefile for your consideration.

-Tom

[-- Attachment #2: Makefile --]
[-- Type: application/octet-stream, Size: 312 bytes --]

CXX=g++

CFLAGS= -W -Wall -pedantic `sdl-config --cflags`

LIBS=`sdl-config --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

OBJS = battle.o character.o

INCS = battle.h character.h

all: battle

battle: $(OBJS)
	$(CXX) -o $@ $(OBJS) $(LIBS)

%.o : %.cpp $(INCS)
	$(CXX) $(CFLAGS) -c $<

clean:
	-rm *.o *~ core* battle

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
@ 2007-12-01 15:14 J.C. Pizarro
  2007-12-01 15:30 ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: J.C. Pizarro @ 2007-12-01 15:14 UTC (permalink / raw)
  To: Tom Browder, gcc-help

On 2007/12/01, "Tom Browder" <tom.browder@gmail.com> wrote:
> On Dec 1, 2007 8:28 AM, Michael Sullivan <michael@espersunited.com> wrote:
> ...
> michael@camille ourrpg $ rm *.o
>
> A target line at the end of Makefile will ease that:
>
> clean:
> <tab>-rm *.o battle *~
>
> Then you can do:
>
>   make clean
>
> > g++ -W -Wall -pedantic -c battle.cpp -o battle.o -I/usr/include/SDL
> > battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
> > int, char*)':
> > battle.cpp:72: warning: missing initializer for member
> > 'SDL_Color::unused'
>
> A C++ error.
>
> > g++ -W -Wall -pedantic -c character.cpp -o character.o
> > -I/usr/include/SDL
> > g++ -o battle battle.o character.o `sdl-config --cflags --libs`
> > -lSDL_image -lSDL_gfx -lSDL_ttf
> > battle.o: In function `battle::battle()':
> > battle.cpp:(.text+0x9e3): undefined reference to
> > `Character::Character()'
> ...
>
> I'm investigating.
>
> -Tom
>
> Tom Browder
> Niceville, Florida
> USA

Why doesn't it publish the parts of source code character.cpp and
battle.cpp related with their uses and definitions?

Is it well written the Character() constructor?

Are there headers?

   J.C.Pizarro

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 14:28                       ` Michael Sullivan
@ 2007-12-01 14:45                         ` Tom Browder
  2007-12-01 15:27                           ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 14:45 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 8:28 AM, Michael Sullivan <michael@espersunited.com> wrote:
...
> michael@camille ourrpg $ rm *.o

A target line at the end of Makefile will ease that:

clean:
<tab>-rm *.o battle *~

Then you can do:

  make clean

> g++ -W -Wall -pedantic -c battle.cpp -o battle.o -I/usr/include/SDL
> battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
> int, char*)':
> battle.cpp:72: warning: missing initializer for member
> 'SDL_Color::unused'

A C++ error.

> g++ -W -Wall -pedantic -c character.cpp -o character.o
> -I/usr/include/SDL
> g++ -o battle battle.o character.o `sdl-config --cflags --libs`
> -lSDL_image -lSDL_gfx -lSDL_ttf
> battle.o: In function `battle::battle()':
> battle.cpp:(.text+0x9e3): undefined reference to
> `Character::Character()'
...

I'm investigating.

-Tom

Tom Browder
Niceville, Florida
USA

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 14:22                     ` Tom Browder
@ 2007-12-01 14:28                       ` Michael Sullivan
  2007-12-01 14:45                         ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 14:28 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help


On Sat, 2007-12-01 at 08:22 -0600, Tom Browder wrote:
> On Dec 1, 2007 7:27 AM, Michael Sullivan <michael@espersunited.com> wrote:
> > My Makefile is now:
> ...
> > %.o : %.cpp
> >         $(CXX) $(CFLAGS) $< -c $@ $(INC)
> 
> The '-c' is misplaced.  The '$@' refers to the object file and the
> '$<' refers to the source file.  So:
> 
>  %.o : %.cpp
>          $(CXX) $(CFLAGS) -c $< -o $@ $(INC)
> 
> -Tom

michael@camille ourrpg $ rm *.o
michael@camille ourrpg $ make
g++ -W -Wall -pedantic -c battle.cpp -o battle.o -I/usr/include/SDL
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
g++ -W -Wall -pedantic -c character.cpp -o character.o
-I/usr/include/SDL
g++ -o battle battle.o character.o `sdl-config --cflags --libs`
-lSDL_image -lSDL_gfx -lSDL_ttf
battle.o: In function `battle::battle()':
battle.cpp:(.text+0x9e3): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xb35): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xb83): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xbd1): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xc16): undefined reference to
`Character::~Character()'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xf19): undefined reference to
`Character::Character()'
battle.cpp:(.text+0x106b): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x10b9): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1107): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x114c): undefined reference to
`Character::~Character()'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0xdb): undefined reference to `vtable for
Character'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0x12d): undefined reference to `vtable for
Character'
collect2: ld returned 1 exit status
make: *** [battle] Error 1
michael@camille ourrpg $ cat Makefile
CXX=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf
INC = -I/usr/include/SDL

all: battle

battle: battle.o character.o 
        $(CXX) -o $@ battle.o character.o $(LIBS)

%.o : %.cpp 
        $(CXX) $(CFLAGS) -c $< -o $@ $(INC)


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 13:27                   ` Michael Sullivan
@ 2007-12-01 14:22                     ` Tom Browder
  2007-12-01 14:28                       ` Michael Sullivan
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 14:22 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 7:27 AM, Michael Sullivan <michael@espersunited.com> wrote:
> My Makefile is now:
...
> %.o : %.cpp
>         $(CXX) $(CFLAGS) $< -c $@ $(INC)

The '-c' is misplaced.  The '$@' refers to the object file and the
'$<' refers to the source file.  So:

 %.o : %.cpp
         $(CXX) $(CFLAGS) -c $< -o $@ $(INC)

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 13:23                 ` Brian Dessent
  2007-12-01 13:27                   ` Michael Sullivan
@ 2007-12-01 13:29                   ` Tom Browder
  1 sibling, 0 replies; 29+ messages in thread
From: Tom Browder @ 2007-12-01 13:29 UTC (permalink / raw)
  To: gcc-help; +Cc: Michael Sullivan

On Dec 1, 2007 7:23 AM, Brian Dessent <brian@dessent.net> wrote:
> Michael Sullivan wrote:
>
> > %.o : %.cpp
> >         $(CXX) $(CFLAGS) $< -o $@ $(INC)
>
> This is wrong, you're missing -c.

You're correct--sorry 'bout that.

-Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 13:23                 ` Brian Dessent
@ 2007-12-01 13:27                   ` Michael Sullivan
  2007-12-01 14:22                     ` Tom Browder
  2007-12-01 13:29                   ` Tom Browder
  1 sibling, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 13:27 UTC (permalink / raw)
  To: gcc-help; +Cc: Tom Browder


On Sat, 2007-12-01 at 05:23 -0800, Brian Dessent wrote:
> Michael Sullivan wrote:
> 
> > %.o : %.cpp
> >         $(CXX) $(CFLAGS) $< -o $@ $(INC)
> 
> This is wrong, you're missing -c.
> 
> Brian

My Makefile is now:

michael@camille ourrpg $ cat Makefile
CXX=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf
INC = -I/usr/include/SDL

all: battle

battle: battle.o character.o 
        $(CXX) -o $@ battle.o character.o $(LIBS)

%.o : %.cpp 
        $(CXX) $(CFLAGS) $< -c $@ $(INC)


michael@camille ourrpg $ make
g++ -W -Wall -pedantic battle.cpp -c battle.o -I/usr/include/SDL
g++: battle.o: No such file or directory
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
make: *** [battle.o] Error 1
michael@camille ourrpg $ make
g++ -W -Wall -pedantic character.cpp -c character.o -I/usr/include/SDL
g++: character.o: No such file or directory
make: *** [character.o] Error 1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 13:16               ` Michael Sullivan
@ 2007-12-01 13:23                 ` Brian Dessent
  2007-12-01 13:27                   ` Michael Sullivan
  2007-12-01 13:29                   ` Tom Browder
  0 siblings, 2 replies; 29+ messages in thread
From: Brian Dessent @ 2007-12-01 13:23 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: Tom Browder, gcc-help

Michael Sullivan wrote:

> %.o : %.cpp
>         $(CXX) $(CFLAGS) $< -o $@ $(INC)

This is wrong, you're missing -c.

Brian

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 13:09             ` Tom Browder
@ 2007-12-01 13:16               ` Michael Sullivan
  2007-12-01 13:23                 ` Brian Dessent
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 13:16 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help


On Sat, 2007-12-01 at 07:09 -0600, Tom Browder wrote:
> On Dec 1, 2007 6:42 AM, Michael Sullivan <michael@espersunited.com> wrote:
> ...
> > > LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf
> 
> Show the output from make initially so I can see the results of the LIBS line.
> 
> What is the 'reset' for in your make commands?
It clears the terminal and the terminal buffer so that I can see only
the current error output.
> 
> A more conventional way to structure the makefile for your situation is:
> 
> CXX=g++
> INC = -I/usr/include/SDL
> 
> all: battle
> 
> battle: battle.o character.o
> <tab>$(CXX) -o $@ battle.o character.o $(LIBS)
> 
> %.o : %.cpp
> <tab>$(CXX) $(CFLAGS) $< -o $@ $(INC)
> 
> 
> That way 'all' is the default target and you can just command 'make'.
> 
> Now, again, I suspect the location of the libraries is part of the
> problem.  Is the library set publicly available (and free)?
> 
> > Is it normal for only portions of make all to run at a time?
> 
> Yes, if it detects a target needing remaking.
> 
> -Tom
> 
> Tom Browder
> Niceville, Florida
> USA

Here's my Makefile now:

LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf
INC = -I/usr/include/SDL

all: battle

battle: battle.o character.o 
	$(CXX) -o $@ battle.o character.o $(LIBS)

%.o : %.cpp 
	$(CXX) $(CFLAGS) $< -o $@ $(INC)

And here's the result of 'make':

michael@camille ourrpg $ make
g++ -W -Wall -pedantic battle.cpp -o battle.o -I/usr/include/SDL
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
/tmp/ccETTf7v.o: In function `battle::loadImage(int, char*)':
battle.cpp:(.text+0x11): undefined reference to `IMG_Load'
battle.cpp:(.text+0x2d): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x71): undefined reference to `SDL_MapRGB'
battle.cpp:(.text+0x9d): undefined reference to `SDL_SetColorKey'
/tmp/ccETTf7v.o: In function `battle::drawLines()':
battle.cpp:(.text+0x18d): undefined reference to `hlineColor'
battle.cpp:(.text+0x1bf): undefined reference to `vlineColor'
battle.cpp:(.text+0x1f1): undefined reference to `hlineColor'
battle.cpp:(.text+0x223): undefined reference to `vlineColor'
battle.cpp:(.text+0x255): undefined reference to `hlineColor'
battle.cpp:(.text+0x287): undefined reference to `hlineColor'
battle.cpp:(.text+0x2b9): undefined reference to `hlineColor'
battle.cpp:(.text+0x2eb): undefined reference to `hlineColor'
battle.cpp:(.text+0x31d): undefined reference to `vlineColor'
battle.cpp:(.text+0x34f): undefined reference to `SDL_UpdateRect'
/tmp/ccETTf7v.o: In function `battle::drawString(int, int, char*)':
battle.cpp:(.text+0x387): undefined reference to `TTF_RenderText_Solid'
battle.cpp:(.text+0x395): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x420): undefined reference to `SDL_UpperBlit'
/tmp/ccETTf7v.o: In function `battle::drawScreen()':
battle.cpp:(.text+0x704): undefined reference to `SDL_UpperBlit'
battle.cpp:(.text+0x73c): undefined reference to `SDL_Flip'
/tmp/ccETTf7v.o: In function `battle::~battle()':
battle.cpp:(.text+0x760): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x778): undefined reference to `TTF_CloseFont'
battle.cpp:(.text+0x793): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x7a5): undefined reference to `SDL_FreeSurface'
/tmp/ccETTf7v.o: In function `battle::~battle()':
battle.cpp:(.text+0x892): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x8aa): undefined reference to `TTF_CloseFont'
battle.cpp:(.text+0x8c5): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x8d7): undefined reference to `SDL_FreeSurface'
/tmp/ccETTf7v.o: In function `battle::battle()':
battle.cpp:(.text+0x9e3): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xa05): undefined reference to `SDL_Init'
battle.cpp:(.text+0xaa9): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xac0): undefined reference to `SDL_Quit'
battle.cpp:(.text+0xaca): undefined reference to `TTF_Init'
battle.cpp:(.text+0xad9): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xb0f): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xb35): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xb5b): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xb83): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xba9): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xbd1): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xbf4): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xc16): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xc2a): undefined reference to `TTF_OpenFont'
battle.cpp:(.text+0xc41): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xc65): undefined reference to `SDL_WM_SetCaption'
battle.cpp:(.text+0xc89): undefined reference to `SDL_SetVideoMode'
battle.cpp:(.text+0xc9e): undefined reference to `SDL_GetError'
/tmp/ccETTf7v.o: In function `main':
battle.cpp:(.text+0xe81): undefined reference to `SDL_Delay'
/tmp/ccETTf7v.o: In function `battle::battle()':
battle.cpp:(.text+0xf19): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xf3b): undefined reference to `SDL_Init'
battle.cpp:(.text+0xfdf): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xff6): undefined reference to `SDL_Quit'
battle.cpp:(.text+0x1000): undefined reference to `TTF_Init'
battle.cpp:(.text+0x100f): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x1045): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x106b): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1091): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x10b9): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x10df): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x1107): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x112a): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x114c): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1160): undefined reference to `TTF_OpenFont'
battle.cpp:(.text+0x1177): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x119b): undefined reference to `SDL_WM_SetCaption'
battle.cpp:(.text+0x11bf): undefined reference to `SDL_SetVideoMode'
battle.cpp:(.text+0x11d4): undefined reference to `SDL_GetError'
collect2: ld returned 1 exit status
make: *** [battle.o] Error 1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 12:43           ` Michael Sullivan
@ 2007-12-01 13:09             ` Tom Browder
  2007-12-01 13:16               ` Michael Sullivan
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 13:09 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 6:42 AM, Michael Sullivan <michael@espersunited.com> wrote:
...
> > LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

Show the output from make initially so I can see the results of the LIBS line.

What is the 'reset' for in your make commands?

A more conventional way to structure the makefile for your situation is:

CXX=g++
INC = -I/usr/include/SDL

all: battle

battle: battle.o character.o
<tab>$(CXX) -o $@ battle.o character.o $(LIBS)

%.o : %.cpp
<tab>$(CXX) $(CFLAGS) $< -o $@ $(INC)


That way 'all' is the default target and you can just command 'make'.

Now, again, I suspect the location of the libraries is part of the
problem.  Is the library set publicly available (and free)?

> Is it normal for only portions of make all to run at a time?

Yes, if it detects a target needing remaking.

-Tom

Tom Browder
Niceville, Florida
USA

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 12:22         ` Tom Browder
@ 2007-12-01 12:43           ` Michael Sullivan
  2007-12-01 13:09             ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 12:43 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help


On Sat, 2007-12-01 at 06:22 -0600, Tom Browder wrote:
> On Dec 1, 2007 5:31 AM, Michael Sullivan <michael@espersunited.com> wrote:
> > On Fri, 2007-11-30 at 22:43 -0600, Tom Browder wrote:
> > > On Nov 30, 2007 10:28 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > > >
> > > > On Fri, 2007-11-30 at 22:01 -0600, Tom Browder wrote:
> > > > > On Nov 30, 2007 7:26 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > > > > > I'm having trouble building my project.  This is my first project I've
> > > > > > worked on that uses make, so I'm having a lot of problems with it.
> > > > > > Here's my Makefile:
> ...
> > > > In file included from battle.cpp:4:
> > > > /usr/local/include/SDL/SDL_gfxPrimitives.h:17:17: error: SDL.h: No such
> > > > file or directory
> > >
> > > You may need the -I (hyphen uppercase i) option to tell gcc where to
> > > find SDL.h.  For instance:
> 
> Look carefully at the gcc manual and the options to g++, the '-I'
> option, which may be used multiple times, gives a path to search for
> include files.
> 
> Now, I can't help the warning at the moment, but the show stoppers are
> the undefined references which are probably defined in the missing
> libraries you asked for on the line:
> 
> LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf
> 
> You probably need to add one or more '-L' options which you use to
> tell gcc where to find libraries (for details, see the gcc manual).
> 
> -Tom
> 
> Tom Browder
> Niceville, Florida
> USA

Actually now, and I find this very strange; I rm *.o and run 'make all'
and it gives me this output:
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
rm: cannot remove `*~': No such file or directory
make: *** [battle.o] Error 1

but battle.o is created.  character.o is not.  The second time I run
make all, both character.o and battle.o exist.  The third time I run
make all, it gives me the following errors:

battle.o: In function `battle::battle()':
battle.cpp:(.text+0x9e3): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xb35): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xb83): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xbd1): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xc16): undefined reference to
`Character::~Character()'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xf19): undefined reference to
`Character::Character()'
battle.cpp:(.text+0x106b): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x10b9): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1107): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x114c): undefined reference to
`Character::~Character()'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0xdb): undefined reference to `vtable for
Character'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0x12d): undefined reference to `vtable for
Character'
collect2: ld returned 1 exit status
rm: cannot remove `*~': No such file or directory
make: *** [all] Error 1

Once again, here is my current Makefile:

CC=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

character.o: character.cpp
	reset; $(CC) $(CFLAGS) -c character.cpp;rm *~

battle.o: battle.cpp
	reset; $(CC) $(CFLAGS) -c battle.cpp -I/usr/include/SDL/; rm *~

all: battle.o character.o
	reset; $(CC) $(CFLAGS) battle.o character.o $(LIBS) -o battle; rm *~

Is it normal for only portions of make all to run at a time?


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01 11:32       ` Michael Sullivan
@ 2007-12-01 12:22         ` Tom Browder
  2007-12-01 12:43           ` Michael Sullivan
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01 12:22 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Dec 1, 2007 5:31 AM, Michael Sullivan <michael@espersunited.com> wrote:
> On Fri, 2007-11-30 at 22:43 -0600, Tom Browder wrote:
> > On Nov 30, 2007 10:28 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > >
> > > On Fri, 2007-11-30 at 22:01 -0600, Tom Browder wrote:
> > > > On Nov 30, 2007 7:26 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > > > > I'm having trouble building my project.  This is my first project I've
> > > > > worked on that uses make, so I'm having a lot of problems with it.
> > > > > Here's my Makefile:
...
> > > In file included from battle.cpp:4:
> > > /usr/local/include/SDL/SDL_gfxPrimitives.h:17:17: error: SDL.h: No such
> > > file or directory
> >
> > You may need the -I (hyphen uppercase i) option to tell gcc where to
> > find SDL.h.  For instance:

Look carefully at the gcc manual and the options to g++, the '-I'
option, which may be used multiple times, gives a path to search for
include files.

Now, I can't help the warning at the moment, but the show stoppers are
the undefined references which are probably defined in the missing
libraries you asked for on the line:

LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

You probably need to add one or more '-L' options which you use to
tell gcc where to find libraries (for details, see the gcc manual).

-Tom

Tom Browder
Niceville, Florida
USA

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01  4:43     ` Tom Browder
@ 2007-12-01 11:32       ` Michael Sullivan
  2007-12-01 12:22         ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01 11:32 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help


On Fri, 2007-11-30 at 22:43 -0600, Tom Browder wrote:
> On Nov 30, 2007 10:28 PM, Michael Sullivan <michael@espersunited.com> wrote:
> >
> > On Fri, 2007-11-30 at 22:01 -0600, Tom Browder wrote:
> > > On Nov 30, 2007 7:26 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > > > I'm having trouble building my project.  This is my first project I've
> > > > worked on that uses make, so I'm having a lot of problems with it.
> > > > Here's my Makefile:
> > > ...
> > > Without even looking in detail at the source I see that the following
> > > line is a compile line and should not have anything but the source
> > > being compiled:
> > >
> > > > battle.o: battle.cpp
> > > >         reset; $(CC) $(CFLAGS) -c battle.cpp character.o $(LIBS); rm *~
> > >
> > > Try changing to:
> > >
> > > battle.o: battle.cpp
> > >          reset; $(CC) $(CFLAGS) -c battle.cpp; rm *~
> > >
> > > and see what happens.
> ...
> > This is make battle after applying the change you suggested,  I deleted
> > *.o just to make sure the object files were cureent:
> >
> > In file included from battle.cpp:4:
> > /usr/local/include/SDL/SDL_gfxPrimitives.h:17:17: error: SDL.h: No such
> > file or directory
> 
> You may need the -I (hyphen uppercase i) option to tell gcc where to
> find SDL.h.  For instance:
> 
> battle.o: battle.cpp
>          reset; $(CC) $(CFLAGS) -c battle.cpp character.o
> -I/path/to/SDL.h; rm *~
> 
> > character.h:8: warning: 'class Character' has virtual functions but
> > non-virtual destructor
> 
> Just change line 11 of character.h to:
> 
>   virtual ~Character();
> 
> -Tom
> 
> Tom Browder
> Niceville, Florida
> USA

OK,  Using the following Makefile:

CC=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

character.o: character.cpp
	reset; $(CC) $(CFLAGS) -c character.cpp;rm *~

battle.o: battle.cpp
	reset; $(CC) $(CFLAGS) -c battle.cpp -I/usr/include/SDL/SDL.h; rm *~

all: battle.o character.o
	reset; $(CC) $(CFLAGS) battle.o character.o $(LIBS) -o battle; rm *~

When I try to make battle, I get this:

cc1plus: error: /usr/include/SDL/SDL.h: not a directory
g++   battle.o   -o battle
g++: battle.o: No such file or directory
g++: no input files
make: *** [battle] Error 1

No battle.o .  When I try it without the SDL.h at the end of the -I
option, I get this:

battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
g++   battle.o   -o battle
battle.o: In function `battle::loadImage(int, char*)':
battle.cpp:(.text+0x11): undefined reference to `IMG_Load'
battle.cpp:(.text+0x2d): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x71): undefined reference to `SDL_MapRGB'
battle.cpp:(.text+0x9d): undefined reference to `SDL_SetColorKey'
battle.o: In function `battle::drawLines()':
battle.cpp:(.text+0x18d): undefined reference to `hlineColor'
battle.cpp:(.text+0x1bf): undefined reference to `vlineColor'
battle.cpp:(.text+0x1f1): undefined reference to `hlineColor'
battle.cpp:(.text+0x223): undefined reference to `vlineColor'
battle.cpp:(.text+0x255): undefined reference to `hlineColor'
battle.cpp:(.text+0x287): undefined reference to `hlineColor'
battle.cpp:(.text+0x2b9): undefined reference to `hlineColor'
battle.cpp:(.text+0x2eb): undefined reference to `hlineColor'
battle.cpp:(.text+0x31d): undefined reference to `vlineColor'
battle.cpp:(.text+0x34f): undefined reference to `SDL_UpdateRect'
battle.o: In function `battle::drawString(int, int, char*)':
battle.cpp:(.text+0x387): undefined reference to `TTF_RenderText_Solid'
battle.cpp:(.text+0x395): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x420): undefined reference to `SDL_UpperBlit'
battle.o: In function `battle::drawScreen()':
battle.cpp:(.text+0x704): undefined reference to `SDL_UpperBlit'
battle.cpp:(.text+0x73c): undefined reference to `SDL_Flip'
battle.o: In function `battle::~battle()':
battle.cpp:(.text+0x760): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x778): undefined reference to `TTF_CloseFont'
battle.cpp:(.text+0x793): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x7a5): undefined reference to `SDL_FreeSurface'
battle.o: In function `battle::~battle()':
battle.cpp:(.text+0x892): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x8aa): undefined reference to `TTF_CloseFont'
battle.cpp:(.text+0x8c5): undefined reference to `SDL_FreeSurface'
battle.cpp:(.text+0x8d7): undefined reference to `SDL_FreeSurface'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0x9e3): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xa05): undefined reference to `SDL_Init'
battle.cpp:(.text+0xaa9): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xac0): undefined reference to `SDL_Quit'
battle.cpp:(.text+0xaca): undefined reference to `TTF_Init'
battle.cpp:(.text+0xad9): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xb0f): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xb35): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xb5b): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xb83): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xba9): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xbd1): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xbf4): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0xc16): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xc2a): undefined reference to `TTF_OpenFont'
battle.cpp:(.text+0xc41): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xc65): undefined reference to `SDL_WM_SetCaption'
battle.cpp:(.text+0xc89): undefined reference to `SDL_SetVideoMode'
battle.cpp:(.text+0xc9e): undefined reference to `SDL_GetError'
battle.o: In function `main':
battle.cpp:(.text+0xe81): undefined reference to `SDL_Delay'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xf19): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xf3b): undefined reference to `SDL_Init'
battle.cpp:(.text+0xfdf): undefined reference to `SDL_GetError'
battle.cpp:(.text+0xff6): undefined reference to `SDL_Quit'
battle.cpp:(.text+0x1000): undefined reference to `TTF_Init'
battle.cpp:(.text+0x100f): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x1045): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x106b): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1091): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x10b9): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x10df): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x1107): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x112a): undefined reference to
`Character::Character(char*, long, long)'
battle.cpp:(.text+0x114c): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1160): undefined reference to `TTF_OpenFont'
battle.cpp:(.text+0x1177): undefined reference to `SDL_GetError'
battle.cpp:(.text+0x119b): undefined reference to `SDL_WM_SetCaption'
battle.cpp:(.text+0x11bf): undefined reference to `SDL_SetVideoMode'
battle.cpp:(.text+0x11d4): undefined reference to `SDL_GetError'
collect2: ld returned 1 exit status
make: *** [battle] Error 1

And, just to avoid confusion, here's my Makefile in it's current
version:

michael@camille ourrpg $ cat Makefile
CC=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

character.o: character.cpp
        reset; $(CC) $(CFLAGS) -c character.cpp;rm *~

battle.o: battle.cpp
        reset; $(CC) $(CFLAGS) -c battle.cpp -I/usr/include/SDL/; rm *~

all: battle.o character.o
        reset; $(CC) $(CFLAGS) battle.o character.o $(LIBS) -o battle;
rm *~


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01  4:28   ` Michael Sullivan
@ 2007-12-01  4:43     ` Tom Browder
  2007-12-01 11:32       ` Michael Sullivan
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01  4:43 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Nov 30, 2007 10:28 PM, Michael Sullivan <michael@espersunited.com> wrote:
>
> On Fri, 2007-11-30 at 22:01 -0600, Tom Browder wrote:
> > On Nov 30, 2007 7:26 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > > I'm having trouble building my project.  This is my first project I've
> > > worked on that uses make, so I'm having a lot of problems with it.
> > > Here's my Makefile:
> > ...
> > Without even looking in detail at the source I see that the following
> > line is a compile line and should not have anything but the source
> > being compiled:
> >
> > > battle.o: battle.cpp
> > >         reset; $(CC) $(CFLAGS) -c battle.cpp character.o $(LIBS); rm *~
> >
> > Try changing to:
> >
> > battle.o: battle.cpp
> >          reset; $(CC) $(CFLAGS) -c battle.cpp; rm *~
> >
> > and see what happens.
...
> This is make battle after applying the change you suggested,  I deleted
> *.o just to make sure the object files were cureent:
>
> In file included from battle.cpp:4:
> /usr/local/include/SDL/SDL_gfxPrimitives.h:17:17: error: SDL.h: No such
> file or directory

You may need the -I (hyphen uppercase i) option to tell gcc where to
find SDL.h.  For instance:

battle.o: battle.cpp
         reset; $(CC) $(CFLAGS) -c battle.cpp character.o
-I/path/to/SDL.h; rm *~

> character.h:8: warning: 'class Character' has virtual functions but
> non-virtual destructor

Just change line 11 of character.h to:

  virtual ~Character();

-Tom

Tom Browder
Niceville, Florida
USA

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01  4:01 ` Tom Browder
@ 2007-12-01  4:28   ` Michael Sullivan
  2007-12-01  4:43     ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01  4:28 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help

On Fri, 2007-11-30 at 22:01 -0600, Tom Browder wrote:
> On Nov 30, 2007 7:26 PM, Michael Sullivan <michael@espersunited.com> wrote:
> > I'm having trouble building my project.  This is my first project I've
> > worked on that uses make, so I'm having a lot of problems with it.
> > Here's my Makefile:
> ...
> 
> Without even looking in detail at the source I see that the following
> line is a compile line and should not have anything but the source
> being compiled:
> 
> > battle.o: battle.cpp
> >         reset; $(CC) $(CFLAGS) -c battle.cpp character.o $(LIBS); rm *~
> 
> Try changing to:
> 
> battle.o: battle.cpp
>          reset; $(CC) $(CFLAGS) -c battle.cpp; rm *~
> 
> and see what happens.
> 
> -Tom
> 
> Tom Browder
> Niceville, Florida
> USA

This is make battle after applying the change you suggested,  I deleted
*.o just to make sure the object files were cureent:

In file included from battle.cpp:4:
/usr/local/include/SDL/SDL_gfxPrimitives.h:17:17: error: SDL.h: No such
file or directory
character.h:8: warning: 'class Character' has virtual functions but
non-virtual destructor
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Undefined References
  2007-12-01  1:26 Michael Sullivan
@ 2007-12-01  4:01 ` Tom Browder
  2007-12-01  4:28   ` Michael Sullivan
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Browder @ 2007-12-01  4:01 UTC (permalink / raw)
  To: Michael Sullivan; +Cc: gcc-help

On Nov 30, 2007 7:26 PM, Michael Sullivan <michael@espersunited.com> wrote:
> I'm having trouble building my project.  This is my first project I've
> worked on that uses make, so I'm having a lot of problems with it.
> Here's my Makefile:
...

Without even looking in detail at the source I see that the following
line is a compile line and should not have anything but the source
being compiled:

> battle.o: battle.cpp
>         reset; $(CC) $(CFLAGS) -c battle.cpp character.o $(LIBS); rm *~

Try changing to:

battle.o: battle.cpp
         reset; $(CC) $(CFLAGS) -c battle.cpp; rm *~

and see what happens.

-Tom

Tom Browder
Niceville, Florida
USA

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Undefined References
@ 2007-12-01  1:26 Michael Sullivan
  2007-12-01  4:01 ` Tom Browder
  0 siblings, 1 reply; 29+ messages in thread
From: Michael Sullivan @ 2007-12-01  1:26 UTC (permalink / raw)
  To: gcc-help

I'm having trouble building my project.  This is my first project I've
worked on that uses make, so I'm having a lot of problems with it.
Here's my Makefile:

CC=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf

character.o: character.cpp
	reset; $(CC) $(CFLAGS) -c character.cpp;rm *~

battle.o: battle.cpp
	reset; $(CC) $(CFLAGS) -c battle.cpp character.o $(LIBS); rm *~

all: battle.o character.o
	reset; $(CC) $(CFLAGS) battle.o character.o $(LIBS) -o battle; rm *~

I've successfully compiled character.o and battle.o, but when I try to
make all, I get a bunch of undefined references errors:

battle.o: In function `battle::battle()':
battle.cpp:(.text+0x9ab): undefined reference to
`Character::Character()'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xecf): undefined reference to
`Character::Character()'
character.o: In function `Character::~Character()':
character.cpp:(.text+0xdb): undefined reference to `vtable for
Character'
character.o: In function `Character::~Character()':
character.cpp:(.text+0xfb): undefined reference to `vtable for
Character'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0x11b): undefined reference to `vtable for
Character'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0x16d): undefined reference to `vtable for
Character'
collect2: ld returned 1 exit status
rm: cannot remove `*~': No such file or directory
make: *** [all] Error 1

My source code is too long to paste into an email (I should say that it
would be impolite to paste all of it into this email), but the full
source code, Makefile, and the errors are at
http://www.espersunited.com/~michael/needhelp.txt .  Please help!



^ permalink raw reply	[flat|nested] 29+ messages in thread

* RE: undefined references
@ 2004-04-27 12:21 Lev Assinovsky
  0 siblings, 0 replies; 29+ messages in thread
From: Lev Assinovsky @ 2004-04-27 12:21 UTC (permalink / raw)
  To: gnuml, gcc-help

Hi Martin!
Could you please show your makefile and sample 
of error messages.

----
Lev Assinovsky
Aelita Software Corporation 
(now is a part of Quest Software)
O&S InTrust Framework Division, Team Leader
ICQ# 165072909


> -----Original Message-----
> From: gnuml [mailto:gnuml@bootweb.nl]
> Sent: Tuesday, April 27, 2004 3:43 PM
> To: gcc-help@gcc.gnu.org
> Subject: undefined references
> 
> 
> Hi,
> 
> I am trying to compile some C++ code and link it to a couple of C++
> libraries (Informix c++ libs). However, I get 'undefined 
> references' for every
> object from the libraries I use. The code compiles fine though.
> Could anybody give me some suggestions on how to test the 
> libraries/what
> to be aware of when linking/what might cause the problem?
> I'm using gcc 3.3.1 and all librarie are in place & specified in the
> makefile.
> Thanks alot!
> 
> Martin
> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: undefined references
       [not found] <B56E6BDB.43%jokada@oceanit.com>
@ 2000-06-15 14:35 ` llewelly
  0 siblings, 0 replies; 29+ messages in thread
From: llewelly @ 2000-06-15 14:35 UTC (permalink / raw)
  To: Jennifer Okada; +Cc: gcc-help

This question originially appeared on gcc-bugs; I am cc-ing to
  gcc-help as it seems more appropriate.

On Thu, 15 Jun 2000, Jennifer Okada wrote:

> Hi.  I'm not sure if this is the right place to ask this question but here
> goes.
> 
> I'm using version egcs -2.91.66 on Red Hat Linux.  I'm trying to compile a
> C++ program, but I'm getting errors about undefined references to 'cout' and
> 'ostream::operator << (int)'.  I included <iostream.h> so I don't know what
> the problem is.  

Without exact commandline and source code, I cannot tell what the problem
  is.

> Any ideas?  Thanks. 

(0) Compile c++ code with 'g++', and not 'gcc'; gcc will not link in
    libstdc++, g++ will.

(1) Do not use -fhonor-std unless you rebuilt your libstdc++ with
    -fhonor-std .

(2) Make sure libstdc++ is installed.


The above are wild guesses; they may or may not apply to you.


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2007-12-02  2:59 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-27 11:43 undefined references gnuml
2004-04-27 12:16 ` Eljay Love-Jensen
  -- strict thread matches above, loose matches on Subject: below --
2007-12-01 15:14 Undefined References J.C. Pizarro
2007-12-01 15:30 ` Tom Browder
2007-12-01  1:26 Michael Sullivan
2007-12-01  4:01 ` Tom Browder
2007-12-01  4:28   ` Michael Sullivan
2007-12-01  4:43     ` Tom Browder
2007-12-01 11:32       ` Michael Sullivan
2007-12-01 12:22         ` Tom Browder
2007-12-01 12:43           ` Michael Sullivan
2007-12-01 13:09             ` Tom Browder
2007-12-01 13:16               ` Michael Sullivan
2007-12-01 13:23                 ` Brian Dessent
2007-12-01 13:27                   ` Michael Sullivan
2007-12-01 14:22                     ` Tom Browder
2007-12-01 14:28                       ` Michael Sullivan
2007-12-01 14:45                         ` Tom Browder
2007-12-01 15:27                           ` Tom Browder
2007-12-01 15:34                             ` Michael Sullivan
2007-12-01 15:43                               ` Tom Browder
2007-12-01 15:44                                 ` Tom Browder
2007-12-01 15:49                                   ` Michael Sullivan
2007-12-01 16:01                                     ` Tom Browder
2007-12-02  2:59                                       ` Tom Browder
2007-12-01 17:45                                 ` Ted Byers
2007-12-01 13:29                   ` Tom Browder
2004-04-27 12:21 undefined references Lev Assinovsky
     [not found] <B56E6BDB.43%jokada@oceanit.com>
2000-06-15 14:35 ` llewelly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).