make/g++ error

If if do
g++ main.o
I get linker errors, which is expected, but
g++ main.o something_else.o
gives
something_else.o: file not recognized: File format not recognized
.

I'm running this through a makefile but the above applies.

Makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
vmtypes = Frame.o Segment.o Video.o Image.o
vmobj = VisualMedia.o $(vmtypes)
vmsup = Signature.o SparseRep.o Matching.o
obj = main.o $(vmsup) $(vmobj)

gpp = g++ -Wall

vid : $(obj)
	$(gpp) -o vid $(obj)
	
main.o : main.cpp Video.o
	$(gpp) -c main.cpp -o main.o
	
VisualMedia.o : VisualMedia.h $(vmsup)
	$(gpp) -c VisualMedia.h -o VisualMedia.o
	
Video.o : Video.h Segment.o VisualMedia.o
	$(gpp) -c Video.h -o Video.o
	
Segment.o : Segment.h Frame.o VisualMedia.o
	$(gpp) -c Segment.h -o Segment.o
	
Frame.o : Frame.h VisualMedia.o
	$(gpp) -c Frame.h -o Frame.o
	
Image.o : Image.h VisualMedia.o
	$(gpp) -c Image.h -o Image.o
	
Signature.o : Signature.h $(vmobj)
	$(gpp) -c Signature.h -o Signature.o
	
SparseRep.o : SparseRep.h Signature.o $(vmobj)
	$(gpp) -c SparseRep.h -o SparseRep.o
	
Matching.o : Matching.h
	$(gpp) -c Matching.h -o Matching.o
	
clean : 
	rm -f $(obj) vid


%make clean; make

rm -f main.o Signature.o SparseRep.o Matching.o VisualMedia.o Frame.o Segment.o Video.o Image.o vid
make: Circular Signature.o <- VisualMedia.o dependency dropped.
make: Circular Signature.o <- Frame.o dependency dropped.
make: Circular Signature.o <- Segment.o dependency dropped.
make: Circular Signature.o <- Video.o dependency dropped.
make: Circular Image.o <- VisualMedia.o dependency dropped.
g++ -Wall -c Image.h -o Image.o
g++ -Wall -c Signature.h -o Signature.o
make: Circular SparseRep.o <- VisualMedia.o dependency dropped.
make: Circular SparseRep.o <- Frame.o dependency dropped.
make: Circular SparseRep.o <- Segment.o dependency dropped.
make: Circular SparseRep.o <- Video.o dependency dropped.
g++ -Wall -c SparseRep.h -o SparseRep.o
g++ -Wall -c Matching.h -o Matching.o
g++ -Wall -c VisualMedia.h -o VisualMedia.o
g++ -Wall -c Frame.h -o Frame.o
g++ -Wall -c Segment.h -o Segment.o
g++ -Wall -c Video.h -o Video.o
g++ -Wall -c main.cpp -o main.o
g++ -Wall -o vid main.o Signature.o SparseRep.o Matching.o VisualMedia.o Frame.o Segment.o Video.o Image.o
Signature.o: file not recognized: File format not recognized
collect2: ld returned 1 exit status
make: *** [vid] Error 1



Any thoughts?
Some questions from me:

1. Why do you have .o that are prerequisites of other .o files ?
For example:
1
2
Segment.o : Segment.h Frame.o VisualMedia.o
	$(gpp) -c Segment.h -o Segment.o
- why does Segment.o depend on VisualMedia.o ??

2. In the commands section you are compiling .h files
For example:
$(gpp) -c Segment.h -o Segment.o why compile header files?
Last edited on
... seems g++ is much happier with .cpp files, making that adjustment now

now I have to deal with a linking or inheritance error... not sure what is going on there.

more soon
Last edited on
1
2
3
1. That's how the gnu make manual does it...
The Segment class inherits from the VisualMedia class so Segment depends on VisualMedia.
The explanation in the manual (in my interpretation) shows it this way. 


I think you maybe misreading - I have the GNU Make manual - in which chapter did you find this suggestion?



With regard to "dependencies" in Makefiles - it is nothing to do with class inheritance.



Thanks guestgulkan, I found my .o confusion.

The example given in the manual (2.2) has the linking rule depending on the .o files but all the others depend on the .h files.

That fixed the circular dependencies too ... :)

Still have some problems though... several multiple definition errors. Not sure what to do about these.



g++ -Wall -c main.cpp
g++ -Wall -c VisualMedia.cpp
g++ -Wall -c Video.cpp
g++ -Wall -c Segment.cpp
g++ -Wall -c Frame.cpp
g++ -Wall -c Image.cpp
g++ -Wall -c Signature.cpp
g++ -Wall -c SparseRep.cpp
g++ -Wall -c Matching.cpp
g++ -Wall -o vid main.o VisualMedia.o Video.o Segment.o Frame.o Image.o Signature.o SparseRep.o Matching.o
Image.o: In function `VisualMedia::whatami()':
Image.cpp:(.text+0xf2): multiple definition of `VisualMedia::whatami()'
VisualMedia.o:VisualMedia.cpp:(.text+0x6c): first defined here
Image.o: In function `VisualMedia::compare(VisualMedia const&)':
Image.cpp:(.text+0x11c): multiple definition of `VisualMedia::compare(VisualMedia const&)'
VisualMedia.o:VisualMedia.cpp:(.text+0x96): first defined here
Image.o: In function `VisualMedia::find(VisualMedia const&)':
Image.cpp:(.text+0x14a): multiple definition of `VisualMedia::find(VisualMedia const&)'
VisualMedia.o:VisualMedia.cpp:(.text+0xc4): first defined here
Image.o: In function `VisualMedia::~VisualMedia()':
Image.cpp:(.text+0x178): multiple definition of `VisualMedia::~VisualMedia()'
VisualMedia.o:VisualMedia.cpp:(.text+0xf2): first defined here
Image.o: In function `VisualMedia::~VisualMedia()':
Image.cpp:(.text+0x278): multiple definition of `VisualMedia::~VisualMedia()'
VisualMedia.o:VisualMedia.cpp:(.text+0x1f2): first defined here
Image.o: In function `VisualMedia::~VisualMedia()':
Image.cpp:(.text+0x378): multiple definition of `VisualMedia::~VisualMedia()'
VisualMedia.o:VisualMedia.cpp:(.text+0x2f2): first defined here
Image.o: In function `VisualMedia::VisualMedia()':
Image.cpp:(.text+0x610): multiple definition of `VisualMedia::VisualMedia()'
VisualMedia.o:VisualMedia.cpp:(.text+0x3f2): first defined here
Image.o: In function `VisualMedia::VisualMedia()':
Image.cpp:(.text+0x6ce): multiple definition of `VisualMedia::VisualMedia()'
VisualMedia.o:VisualMedia.cpp:(.text+0x4b0): first defined here
collect2: ld returned 1 exit status
make: *** [vid] Error 1



VisualMedia.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef VISUALMEDIA_H_INCLUDED_
#define VISUALMEDIA_H_INCLUDED_

#include <iostream>

#include "Signature.h"
#include "SparseRep.h"
#include "Matching.h"

class VisualMedia
{
  private:
    Signature _signature;
    SparseRep _sparserep;
    Matching _matching;

  protected:
    VisualMedia();

  public:
    virtual ~VisualMedia();
    virtual void find(const VisualMedia &vm);
    virtual void compare(const VisualMedia &vm);
    virtual void whatami();
};

#endif


VisualMedia.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "VisualMedia.h"

VisualMedia::VisualMedia()
{ std::cout << "VisualMedia::VisualMedia()" << std::endl; }

VisualMedia::~VisualMedia()
{ std::cout << "VisualMedia::~VisualMedia()" << std::endl; }

void VisualMedia::find(const VisualMedia &vm)
{ std::cout << "VisualMedia::find()" << std::endl;}

void VisualMedia::compare(const VisualMedia &vm)
{ std::cout << "VisualMedia::compare()" << std::endl; }

void VisualMedia::whatami()
{ std::cout << "--- I am a VisualMedia object ---" << std::endl; }


Image.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef IMAGE_H_INCLUDED_
#define IMAGE_H_INCLUDED_

#include <iostream>

#include "VisualMedia.cpp"

class Image: public VisualMedia
{
  public:
    Image();
    virtual ~Image();
    virtual void find(const VisualMedia &vm);
    virtual void compare(const VisualMedia &vm);
    virtual void whatami();

    void edgeDetect() { std::cout << "Image::edgeDetect()" << std::endl; }
};

#endif



Image.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "Image.h"

Image::Image()
{ std::cout << "Image::Image()" << std::endl; }

Image::~Image()
{ std::cout << "Image::~Image()" << std::endl; }

void Image::find(const VisualMedia &vm)
{ std::cout << "Image::find()" << std::endl;}

void Image::compare(const VisualMedia &vm)
{ std::cout << "Image::compare()" << std::endl; }

void Image::whatami()
{ std::cout << "--- I am a Image object ---" << std::endl; }


Video, Segment, and Frame are similar.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef IMAGE_H_INCLUDED_
#define IMAGE_H_INCLUDED_

#include <iostream>

#include "VisualMedia.cpp"//<<================  Shouldn't this be #include "VisualMedia.h" 

class Image: public VisualMedia
{
  public:
    Image();
    virtual ~Image();
    virtual void find(const VisualMedia &vm);
    virtual void compare(const VisualMedia &vm);
    virtual void whatami();

    void edgeDetect() { std::cout << "Image::edgeDetect()" << std::endl; }
};

#endif
Last edited on
wow... I must be blind. I think I have lots of those :(

Thanks

EDIT:

It was just that one, luckily I posted it. Everything seems to be working now. I thought I had some fundamental problems (g++, make, inheritance) but turns out not.

Thanks for your help.
Last edited on
Topic archived. No new replies allowed.