0

I have a test.cpp file, written for using boost unit test.

test.cpp :
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp> 
.........

I am trying to linking this test.cpp with a library named liba.

g++ test.cpp -L/liba_directory -la  

keeps giving error message that one class in my liba is not declared. At the same time, another class in the same library can be found.

as a positive control, I linked this library with my main file, which works fine.

g++ main.cpp -L/liba_directory -la

passes compilation perfectly fine.

Looks like files for one specific class in my compiled library can't be seen by my test file, but perfectly accessible for my main file. Can anyone give me some suggestions?

ildjarn
  • 59,718
  • 8
  • 115
  • 201
user1470393
  • 177
  • 3
  • 12
  • Does it really say not "declared"? If so, it sounds like a compiler error not a linker error, and so you probably forgot to include a header in test.cpp – Jonathan Wakely Aug 21 '12 at 20:36
  • Yes, " " was not declared in this scope. I will have to say I did include correct header file. I am also sure it is not namespace problem. I am confused by why the main function works, but not the test function. – user1470393 Aug 22 '12 at 02:25
  • I finally solved the problem, but I still don't understand. here is what I did: – user1470393 Aug 22 '12 at 03:37
  • I finally solved the problem, but I don't understand why. Here is what I did: I copy the file to a different name, and then everything works. like cp this_header.h this_header2.h Of course, also change the including file name accordingly. Anyone help me on an explanation? I am on sygwin. – user1470393 Aug 22 '12 at 03:38
  • it's not possible to know, because you haven't actually shown any code (e.g. are you doing `#include ""` or `#include <>`? what's the real name of the header? I assume it's not "this_header.h" because that's a stupid name for a header) and haven't shown the error you get. If you expect useful answers then ask a useful question. – Jonathan Wakely Aug 22 '12 at 15:36
  • hi, Johnathan, the file name is "log_book.h" changed to "log_book2.h". To include it, I use #include "log_book2.h" from both main.cpp and test.cpp and log_book.cpp. As best as I see this problem, only the file name change per se solved it. But that is not something logic. So I would love to hear any other thoughts for an explanation. I really appreciate your help. – user1470393 Aug 22 '12 at 19:16
  • are `main.cpp` and `test.cpp` in the same directory as `log_book.h`? – Jonathan Wakely Aug 22 '12 at 20:06

0 Answers0