sinhayash
sinhayash

Reputation: 2803

Errors while compiling DeSiNe

While I run make build for the project DeSiNe [Click to go to github page], I am getting the error ‘Topology’ does not name a type

$ make build
mkdir -m 755 -p obj/Algorithm
g++ -Wall -DNO_TIMER -DNO_TRACES  -O3 -funroll-loops -finline-functions -fexpensive-optimizations -Isrc -o obj/Algorithm/Algorithm.o -c src/Algorithm/Algorithm.cpp
In file included from src/Network/TopologyFactory.h:21:0,
                 from src/Network/Topology.h:25,
                 from src/Network/Flow.h:20,
                 from src/Algorithm/Algorithm.h:20,
                 from src/Algorithm/Algorithm.cpp:14:
src/RandomVariables/RandomNumberGenerator.h: In member function ‘double RandomNumberGenerator::generate()’:
src/RandomVariables/RandomNumberGenerator.h:158:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         return (double) 2.0 - (*(float*) &itemp);
                                           ^
In file included from src/Network/Topology.h:25:0,
                 from src/Network/Flow.h:20,
                 from src/Algorithm/Algorithm.h:20,
                 from src/Algorithm/Algorithm.cpp:14:
src/Network/TopologyFactory.h: At global scope:
src/Network/TopologyFactory.h:76:5: error: ‘Topology’ does not name a type
     Topology* create(const TString &description);
     ^
src/Network/TopologyFactory.h:84:48: error: ‘Topology’ has not been declared
     void build(const NodePairDeque &nodepairs, Topology* topology);
                                                ^
src/Network/TopologyFactory.h:92:5: error: ‘Topology’ does not name a type
     Topology* createTopologyAdjacency(const TString &description);
     ^
src/Network/TopologyFactory.h:103:5: error: ‘Topology’ does not name a type
     Topology* createTopologyBarabasi(const TString &description);
     ^
src/Network/TopologyFactory.h:112:5: error: ‘Topology’ does not name a type
     Topology* createTopologyErdos(const TString &description);
     ^
src/Network/TopologyFactory.h:120:5: error: ‘Topology’ does not name a type
     Topology* createTopologyFile(const TString &description);
     ^
src/Network/TopologyFactory.h:129:5: error: ‘Topology’ does not name a type
     Topology* createTopologyFull(const TString &description);
     ^
src/Network/TopologyFactory.h:138:5: error: ‘Topology’ does not name a type
     Topology* createTopologyGrid2D(const TString &description);
     ^
src/Network/TopologyFactory.h:147:5: error: ‘Topology’ does not name a type
     Topology* createTopologyRandom(const TString &description);
     ^
make: *** [Algorithm/Algorithm] Error 1

but the included Topology.h does contain

class Topology : public AbstractNetworkElement
{
    // Friend(s)

How to resolve?

EDIT: Adding forward declaration for class Topology gives further error:

In file included from src/Algorithm/SamcraBAlgorithm.h:22:0,
                 from src/Algorithm/SamcraBAlgorithm.cpp:17:
src/Utils/TString.h:25:7: error: using typedef-name ‘Types::TString’ after ‘class’
 class TString
       ^
In file included from src/LinkStateUpdate/LinkStateUpdateVisitor.h:23:0,
                 from src/Network/Link.h:19,
                 from src/Network/Topology.h:23,
                 from src/Network/Flow.h:20,
                 from src/Algorithm/Algorithm.h:22,
                 from src/Algorithm/SamcraBAlgorithm.cpp:16:
src/Utils/Types.h:65:24: note: ‘Types::TString’ has a previous declaration here
  typedef deque<string> TString;
                        ^
make: *** [Algorithm/SamcraBAlgorithm] Error 1

Upvotes: 3

Views: 100

Answers (2)

codestation
codestation

Reputation: 3498

Basically the project has four main compilation problems:

  • Circular include dependency between TopologyFactory and Topology classes.
  • Including TString.h header directly when is meant to be used as a typedef.
  • Missing cstdlib/cstdio includes.
  • Member initialization in class definition (not available until C++11).

The fix for the first one involves removing TopologyFactory from the Topology header, thus breaking the circular include dependency. Then including the TopologyFactory header where is needed.

The second one is easy to fix: just remove the TString header includes so it uses the definition at Utils/Types.h by default.

Third fix is trivial: just add the cstdio/cstdlib includes where needed.

The last fix involves moving the static initialization to the definition file (maybe the author was using an old compiler with an extension who allowed this type of initialization).

I made a patch on this gist so you can see the changes. The project compiles with g++ 5.2.1 on Ubuntu 15.10.

Upvotes: 2

Vadim Key
Vadim Key

Reputation: 1234

There is a cross-reference in the code.

Topology.h includes TopologyFactory.h and vice versa TopologyFactory.h included Topology.h

The most easy way to fix it add forward declaration for class Topology into TopologyFactory.h:

#ifndef TOPOLOGYFACTORY_H
#define TOPOLOGYFACTORY_H

...

class Topology;

class TopologyFactory
{

More correct approach would be try to solve these dependencies, i.e. don't include TopologyNetwork.h in Topology.h and then in all cpp files which using TopologyNetwork and Topology add two include directives:

/*                                                                                                                                                                                             
        source file DesineModel.cpp for class: DesineModel                                                                                                                               

     ... 
*/

...  

#include "Network/Topology.h"
#include "Network/TopologyFactory.h"

...

Upvotes: 1

Related Questions