By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

About to commit suicide - Linker error

P: 1
Hi,

I must have hit my head real hard sometime these days as after starting to use a redhat 9 machine I cannot link a stupid c++ project. I've spent 3 days googling down to results page 20 and used severeal other search engines. I am desperate!

Any help highly appreciated:

Expand|Select|Wrap|Line Numbers
  1.  cfg.cpp: 
  2. #include <iostream>
  3. #include "Cfg.h"
  4.  
  5. Cfg::Cfg()
  6. {
  7.     int i=0;
  8. }
  9. -------------
  10. Cfg.h:
  11. #ifndef CFG_H
  12. #define CFG_H
  13.  
  14. class Cfg
  15. {
  16. public:
  17.  
  18.     Cfg();
  19.  
  20. };
  21.  
  22. #endif
  23. -------------
  24. DAO.cpp:
  25. #include "Cfg.h"
  26. #include "DAO.h"
  27. using namespace std;
  28.  
  29. DAO::DAO( )
  30. {
  31.     int i=0;
  32. }
  33. -------------
  34. DAO.h:
  35. #ifndef DAO_H
  36. #define DAO_H
  37.  
  38. #include "Cfg.h"
  39. class DAO
  40. {
  41. public:
  42.  
  43.     explicit DAO();
  44.  
  45. };
  46.  
  47. #endif
  48. -------------
  49. DBHelper.cpp:
  50. #include "Cfg.h"
  51. #include "DAO.h"
  52. #include "DBHelper.h"
  53. using namespace std;
  54.  
  55. DBHelper::DBHelper()
  56. {
  57.     int i=0;
  58. }
  59. ---------------
  60. DBHelper.h
  61. #ifndef DBHELPER_H
  62. #define DBHELPER_H
  63.  
  64. #include "Cfg.h"
  65. using namespace std;
  66.  
  67. class DBHelper
  68. {
  69. public:
  70.  
  71.     explicit DBHelper();
  72.  
  73. };
  74.  
  75. #endif
  76. -----------------
  77. proba.c
  78. #include <iostream>
  79. using namespace std;
  80. #include "DAO.cpp"
  81.  
  82. int main (void)
  83. {
  84. cout<<"Hello world";
  85. }
  86.  
  87. -----------------
  88.  
This is madness for me:

- g++ -c fileX.cpp: Each file produces it's .o without problems
- 'g++ -o proba DAO.o Cfg.o DBHelper.o proba.o' produces:

Expand|Select|Wrap|Line Numbers
  1.  [cc] 0 total files to be compiled. 
  2. [cc] Starting link
  3. [cc] bin/proba.o(.text+0x0): In function `DAO::DAO[not-in-charge]()':
  4. [cc] /home/bereng/probaLinker/lib/DAO.cpp:6: multiple definition of `DAO::DAO[not-in-charge]()'
  5. [cc] bin/lib/DAO.o(.text+0x0):/home/bereng/probaLinker/lib/DAO.cpp:6: first defined here
  6. [cc] bin/proba.o(.text+0x10): In function `DAO::DAO[in-charge]()':
  7. [cc] /home/bereng/probaLinker/lib/DAO.cpp:6: multiple definition of `DAO::DAO[in-charge]()'
  8. [cc] bin/lib/DAO.o(.text+0x10):/home/bereng/probaLinker/lib/DAO.cpp:6: first defined here
  9. [cc] collect2: ld returned 1 exit status
  10.  
HELP! PLEASE!
Apr 20 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
In proba.cpp

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. #include "DAO.cpp"
  4.  
surely that should be

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. #include "DAO.h"
  4.  
Apr 20 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.