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...
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.
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.