Hi,

there were some global operator definitions in the header file which
caused the multiple definition errors. Apply the attached patch
to fix the problem.

Curt: I would like to suggest to rename "stream.h" to "logstream.h"
because this is also the name of the class and it gives a better
idea of what the header file is for.

Best Regards,

        Andreas

Paul Butcher wrote:
I am having problems with the code within <log4cxx/stream.h>. Using it in a single source file works fine, but when I try to use it more than once, I get the following when linking:

In function `operator<<(log4cxx::logstream&, char const*)':
log4cxx/stream.h:153: multiple definition of `operator<<(log4cxx::logstream&, char const*)'
[...]

--
Andreas Fester
mailto:[EMAIL PROTECTED]
WWW: http://littletux.homelinux.org
ICQ: 326674288
Index: include/log4cxx/stream.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/stream.h,v
retrieving revision 1.11
diff -u -r1.11 stream.h
--- include/log4cxx/stream.h    11 Mar 2005 06:34:48 -0000      1.11
+++ include/log4cxx/stream.h    4 Jun 2005 08:49:20 -0000
@@ -147,58 +147,35 @@
 
 }  // namespace log4cxx
 
+
 #if LOG4CXX_HAS_WCHAR_T
 log4cxx::logstream& operator<<(
   ::log4cxx::logstream& lhs,
-  const char* rhs) {
-  LOG4CXX_DECODE_CHAR(tmp, rhs);
-  LOG4CXX_ENCODE_WCHAR(msg, tmp);
-  lhs.getStream() << msg;
-  return lhs;
-}
+  const char* rhs);
 #else
 log4cxx::logstream& operator<<(
   ::log4cxx::logstream& lhs,
-  const char* rhs) {
-  LOG4CXX_DECODE_CHAR(tmp, rhs);
-  LOG4CXX_ENCODE_CHAR(msg, tmp);
-  lhs.getStream() << msg;
-  return lhs;
-}
+  const char* rhs);
 #endif
 
-
 ::log4cxx::logstream& operator<<(
    ::log4cxx::logstream& lhs,
-   const ::log4cxx::spi::LocationInfo& rhs) {
-   lhs.setLocation(rhs);
-   return lhs;
-}
+   const ::log4cxx::spi::LocationInfo& rhs);
 
 
 ::log4cxx::logstream& operator<<(
    ::log4cxx::logstream& lhs,
-   const ::log4cxx::spi::LocationFlush& rhs) {
-   lhs.flush(rhs);
-   return lhs;
-}
+   const ::log4cxx::spi::LocationFlush& rhs);
+
 
 ::log4cxx::logstream& operator<<(
    ::log4cxx::logstream& lhs,
-   const ::log4cxx::LevelPtr& rhs) {
-   lhs.setLevel(rhs);
-   return lhs;
-}
+   const ::log4cxx::LevelPtr& rhs);
 
 
 ::log4cxx::logstream& operator<<(
    ::log4cxx::logstream& lhs,
-   ::std::ios_base& (*manip)(::std::ios_base&)) {
-     (*manip)(lhs);
-   return lhs;
-}
-
-
+   ::std::ios_base& (*manip)(::std::ios_base&));
 
 
 //
@@ -214,6 +191,7 @@
    return lhs;
 }
 
+
 #if !defined(LOG4CXX_ENDMSG)
 #define LOG4CXX_ENDMSG LOG4CXX_LOCATION_FLUSH
 #endif
Index: src/Makefile.am
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/Makefile.am,v
retrieving revision 1.30
diff -u -r1.30 Makefile.am
--- src/Makefile.am     1 Jun 2005 18:40:26 -0000       1.30
+++ src/Makefile.am     4 Jun 2005 08:49:21 -0000
@@ -67,6 +67,7 @@
         loggingevent.cpp \
         loglog.cpp \
         logmanager.cpp \
+        logstream.cpp \
         manualtriggeringpolicy.cpp \
         messagepatternconverter.cpp \
         methodlocationpatternconverter.cpp \
Index: src/logstream.cpp
===================================================================
RCS file: src/logstream.cpp
diff -N src/logstream.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/logstream.cpp   4 Jun 2005 08:49:21 -0000
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <log4cxx/stream.h>
+
+#if LOG4CXX_HAS_WCHAR_T
+log4cxx::logstream& operator<<(
+  ::log4cxx::logstream& lhs,
+  const char* rhs) {
+  LOG4CXX_DECODE_CHAR(tmp, rhs);
+  LOG4CXX_ENCODE_WCHAR(msg, tmp);
+  lhs.getStream() << msg;
+  return lhs;
+}
+#else
+log4cxx::logstream& operator<<(
+  ::log4cxx::logstream& lhs,
+  const char* rhs) {
+  LOG4CXX_DECODE_CHAR(tmp, rhs);
+  LOG4CXX_ENCODE_CHAR(msg, tmp);
+  lhs.getStream() << msg;
+  return lhs;
+}
+#endif
+
+::log4cxx::logstream& operator<<(
+   ::log4cxx::logstream& lhs,
+   const ::log4cxx::spi::LocationInfo& rhs) {
+   lhs.setLocation(rhs);
+   return lhs;
+}
+
+
+::log4cxx::logstream& operator<<(
+   ::log4cxx::logstream& lhs,
+   const ::log4cxx::spi::LocationFlush& rhs) {
+   lhs.flush(rhs);
+   return lhs;
+}
+
+::log4cxx::logstream& operator<<(
+   ::log4cxx::logstream& lhs,
+   const ::log4cxx::LevelPtr& rhs) {
+   lhs.setLevel(rhs);
+   return lhs;
+}
+
+
+::log4cxx::logstream& operator<<(
+   ::log4cxx::logstream& lhs,
+   ::std::ios_base& (*manip)(::std::ios_base&)) {
+     (*manip)(lhs);
+   return lhs;
+}

Reply via email to