problem linking header files.

I have a c++ program running in ubuntu. When I try executing it, the header files are not getting linked with the source code. What really can be the problem? Thanks for the help...
Huh?

(Are you using templates?)
I am not conversant with C++ yet to recognise templates. I will paste the program here. None of the header files is getting linked
#include <iostream>

#include "common-defs.h"
#include "simulator.h"
#include "node.h"
#include "bgp.h"

using namespace std;

int main(int argc,char ** argv)
{
Simulator Sim;

Node::DefaultShape(Node::CIRCLE);

Trace* tr= Trace::Instance();
tr->Open("bgpExample1.txt");

Uniform startRng(0,0.1);

Node* node = new Node();
BGP* bgpRouter = new BGP(0);

bgpRouter->AttachNode(node);
bgpRouter->StartAt(0.1);

bgpRouter->config_file("./bgpd1.conf");

node->SetLocation(4,0);

Sim.Progress(1);
Sim.StopAt(400);
cout << "Starting Simulation" << endl;
Sim.Run();
cout << "Simulation complete" << endl;
}
Correction: #include<iostream> is getting linked correctly, the rest are not..
Header files don't get "linked".

I think you are trying to say that your project has several .cpp files -- main.cpp, simulator.cpp,
node.cpp, and bgp.cpp and that none of the functions implemented in simulator.cpp, node.cpp,
and bgp.cpp are getting linked into your execution (unresolved externals).

If that is the case, you need to ensure that you are linking all of the .o or .obj files into the
executable, and not just main.o/main.obj.
Yeah, that was exactly what I was trying to say. How am I to make sure that I am linking all the object files into the executable?
I am posting the errors here for your reference. Thanks for your help.

bgpExample1.cc:6:25: error: common-defs.h: No such file or directory
bgpExample1.cc:7:23: error: simulator.h: No such file or directory
bgpExample1.cc:8:18: error: node.h: No such file or directory
bgpExample1.cc:9:17: error: bgp.h: No such file or directory
bgpExample1.cc: In function ‘int main(int, char**)’:
bgpExample1.cc:15: error: ‘Simulator’ was not declared in this scope
bgpExample1.cc:15: error: expected `;' before ‘Sim’
bgpExample1.cc:17: error: ‘Node’ has not been declared
bgpExample1.cc:17: error: ‘Node’ has not been declared
bgpExample1.cc:19: error: ‘Trace’ was not declared in this scope
bgpExample1.cc:19: error: ‘tr’ was not declared in this scope
bgpExample1.cc:19: error: ‘Trace’ is not a class or namespace
bgpExample1.cc:22: error: ‘Uniform’ was not declared in this scope
bgpExample1.cc:22: error: expected `;' before ‘startRng’
bgpExample1.cc:24: error: ‘Node’ was not declared in this scope
bgpExample1.cc:24: error: ‘node’ was not declared in this scope
bgpExample1.cc:24: error: expected type-specifier before ‘Node’
bgpExample1.cc:24: error: expected `;' before ‘Node’
bgpExample1.cc:25: error: ‘BGP’ was not declared in this scope
bgpExample1.cc:25: error: ‘bgpRouter’ was not declared in this scope
bgpExample1.cc:25: error: expected type-specifier before ‘BGP’
bgpExample1.cc:25: error: expected `;' before ‘BGP’
bgpExample1.cc:34: error: ‘Sim’ was not declared in this scope
I get tired of saying this because nobody ever actually does it but it would explain everything:
> man gcc

Pay particular attention to the -I, -L, and -l options.

To elaborate, beginning with the first error message, the compiler does not know where to find common-defs.h. Start be locating it and verifying the path in the #include statement. Note that double quotes and angle brackets may make a difference in where the file should be located. Additionally, the compiler can accept additionally include paths to search for include files. After these are worked out, the No such file or directory errors should go away.

Then you'll probably run into undefined identifier errors. Fortunately, by this point the program compiles--however, it does not link. Undefined identifier errors are caused by either forgetting to provide definitions or not linking with the object file that contains the definitions. The compiler must be told to include the libraries that it uses and there are also library include paths.

Then it may be necessary to tell the executable where to find shared object files, if there were any, in order to run the program. The LD_LIBRARY_PATH environment variable is a colon-delimited list of library paths.

Hope this helps.
Last edited on
bgpExample1.cc:6:25: error: common-defs.h: No such file or directory


Are your header files in the same folder as your bgpExample1.cc file?

Are you spelling the file names correctly?

EDIT: just to make clear -- this isn't a linker problem. The compiler is not finding the header files and thus the #includes are failing.
Last edited on
Topic archived. No new replies allowed.