Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #ifndef __IL_NOTIFY_H__
  2. #define __IL_NOTIFY_H__
  3.  
  4. #include <string>
  5. #include "Poco/Logger.h"
  6. #include "Poco/LogStream.h"
  7.  
  8. using Poco::Logger;
  9. using Poco::LogStream;
  10.  
  11. namespace mynamespace
  12. {
  13. // Get logger. Inherits root channel
  14. LogStream lstr(Logger::get("MyLogger"));
  15.  
  16. // From any other class, call logger this way:
  17. //lstr << "This is a test" << std::endl;
  18. }
  19.  
  20. #endif
  21.  
  22. #include "IL_Class1.h"
  23. #include "IL_Notify.h"
  24.  
  25. namespace mynamespace {
  26.  
  27. void IL_Class1::foo()
  28. {
  29. // Stuff...
  30.  
  31. lstr << "This is a test msg from IL_Class1::foo" << std::endl;
  32. }
  33. }
  34.  
  35. #include "IL_Class2.h"
  36. #include "IL_Notify.h"
  37.  
  38. namespace mynamespace {
  39.  
  40. void IL_Class2::bar()
  41. {
  42. // Stuff...
  43.  
  44. lstr << "This is a test msg from IL_Class2::bar" << std::endl;
  45. }
  46. }
  47.  
  48. # Set search path to find PocoConfig.cmake
  49. set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules/)
  50.  
  51.  
  52. # Look for needed packages
  53. find_package(Poco REQUIRED)
  54.  
  55. # Now, we can use poco
  56. include_directories(
  57. ${Poco_INCLUDE_DIRS}
  58. ${CMAKE_CURRENT_SOURCE_DIR}/include
  59. )
  60.  
  61. # Libraries which we are linking against
  62. link_directories(
  63. ${Poco_LIBRARY_DIRS}
  64. )
  65.  
  66. # Get all the cpp files to build my library
  67. file(GLOB_RECURSE all_sources
  68. ${CMAKE_CURRENT_SOURCE_DIR}/src/IL_Class1.cpp
  69. ${CMAKE_CURRENT_SOURCE_DIR}/src/IL_Class2.cpp
  70. )
  71.  
  72. # Library creation
  73. add_library(mylib SHARED ${all_sources})
  74.  
  75. CMakeFiles/mylib.dir/src/IL_Class2.cpp.o:(.bss+0x0): multiple definition of `mynamespace::lstr'
  76. CMakeFiles/mylib.dir/src/IL_Class1.cpp.o:(.bss+0x0): first defined here
  77. collect2: error: ld returned 1 exit status
  78. make[2]: *** [libmylib.so] Error 1
  79. make[1]: *** [CMakeFiles/mylib.dir/all] Error 2
  80. make: *** [all] Error 2
  81.  
  82. #ifndef __IL_NOTIFY_H__
  83. #define __IL_NOTIFY_H__
  84.  
  85. #include <string>
  86. #include "Poco/Logger.h"
  87. #include "Poco/LogStream.h"
  88.  
  89. using Poco::Logger;
  90. using Poco::LogStream;
  91.  
  92. namespace openil
  93. {
  94. // Get logger. Inherits root channel
  95. extern LogStream lstr;
  96. }
  97.  
  98. #endif
  99.  
  100. #include "IL_Notify.h"
  101.  
  102. namespace openil
  103. {
  104. // TODO: More flexibility here: more channels, different formatting...
  105. // Maybe a IL_Utils function should do that
  106.  
  107. // Get logger. Inherits root channel
  108. LogStream lstr(Logger::get("OpenILLogger"));
  109.  
  110. // From any other class, call logger this way:
  111. //lstr << "This is a test" << std::endl;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement