From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13996 invoked by alias); 10 Sep 2004 10:17:19 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 13983 invoked from network); 10 Sep 2004 10:17:17 -0000 Received: from unknown (HELO baldur.globalsymmetry.com) (66.92.149.152) by sourceware.org with SMTP; 10 Sep 2004 10:17:17 -0000 Received: from ljosalfr.globalsymmetry.com (ljosalfr.globalsymmetry.com [192.168.0.27]) by baldur.globalsymmetry.com (8.12.3/8.12.3/SuSE Linux 0.6) with ESMTP id i8AAIbEm005948 for ; Fri, 10 Sep 2004 06:18:37 -0400 Received: from ljosalfr.globalsymmetry.com (localhost [127.0.0.1]) by ljosalfr.globalsymmetry.com (8.12.10/8.12.10/SuSE Linux 0.7) with ESMTP id i8AAGlSk016985 for ; Fri, 10 Sep 2004 06:16:47 -0400 Received: from localhost (localhost [[UNIX: localhost]]) by ljosalfr.globalsymmetry.com (8.12.10/8.12.10/Submit) id i8AAGlij016984 for gcc@gcc.gnu.org; Fri, 10 Sep 2004 06:16:47 -0400 X-Authentication-Warning: ljosalfr.globalsymmetry.com: hattons set sender to hattons@globalsymmetry.com using -f From: "Steven T. Hatton" Organization: Global Symmetry To: gcc@gcc.gnu.org Subject: Re: Fwd: Linking public: static const members in lib*.a's Date: Fri, 10 Sep 2004 10:40:00 -0000 User-Agent: KMail/1.7 References: <200409100243.19933.hattons@globalsymmetry.com> <87brgey0lk.fsf@deneb.enyo.de> In-Reply-To: <87brgey0lk.fsf@deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200409100616.46719.hattons@globalsymmetry.com> X-SW-Source: 2004-09/txt/msg00599.txt.bz2 On Friday 10 September 2004 04:44, Florian Weimer wrote: > * Steven T. Hatton: > > Sorry about the big code dump. I tried to get it down to the minimum > > required to demonstrate the problem. > > It's still not minimal (you should be able to reproduce it with two > preprocessed translation units), and the file names you indicated > appear to be wrong. These filenames should all be correct. I guess I intuitively knew that trying to reproduce the problem with only two translation units would fail. It seems the problem has to do with secondary linkage. I'm going to take the following and move ColorTest.* to src/sth and src/sth/[PR]* to util, and try again, just to be sure. ################## # ./src/sth/Makefile.am ################## INCLUDES = $(all_includes) lib_LIBRARIES = libsth.a libsth_a_SOURCES = RgbColor.cpp noinst_HEADERS = RgbColor.h Printable_IF.h ################## EOF ################## ################## # ./src/Makefile.am ################## INCLUDES = -I$(top_srcdir)/src/sth $(all_includes) bin_PROGRAMS = testlibs testlibs_SOURCES = main.cpp ColorTest.cpp testlibs_LDFLAGS = $(all_libraries) testlibs_LDADD = $(top_builddir)/src/sth/libsth.a SUBDIRS = sth ################## EOF ################## ################## # ./Makefile.am ################## SUBDIRS = src ################## EOF ################## ################## # ./configure.ac ################## # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) AC_INIT(FULL-PACKAGE-NAME, 0.1, bugs@insects.ant) AC_CONFIG_SRCDIR([src/main.cpp]) AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE # Checks for programs. AC_PROG_CXX AC_PROG_CC # Checks for libraries. AC_PROG_RANLIB # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_C_INLINE # Checks for library functions. AC_CONFIG_FILES([Makefile src/Makefile src/sth/Makefile]) AC_OUTPUT ################## EOF ################## /****************** * ./src/sth/Printable_IF.h ******************/ #ifndef PRINTABLE_IF_H #define PRINTABLE_IF_H #include namespace sth { namespace util { class Printable_IF { public: Printable_IF() {} virtual ~Printable_IF() {} virtual std::ostream& print(std::ostream& out) const = 0; }; inline std::ostream& operator<<(std::ostream& out, const Printable_IF& pif) { return pif.print(out); } } } #endif /****************** EOF ******************/ /****************** * ./src/sth/RgbColor.h ******************/ #ifndef UTILRGBCOLOR_H #define UTILRGBCOLOR_H #include "Printable_IF.h" namespace sth { namespace util { /** @author Steven T. Hatton */ class RgbColor : public Printable_IF { unsigned char m_r; unsigned char m_g; unsigned char m_b; public: RgbColor(const unsigned char& r=255, const unsigned char& g=127, const unsigned char& b=127); unsigned char R() const; void R(const unsigned char& r); unsigned char G() const; void G(const unsigned char& g); unsigned char B() const; void B(const unsigned char& b); std::ostream& print(std::ostream& out) const; static const RgbColor RED; }; inline unsigned char RgbColor::R() const { return m_r; } inline void RgbColor::R(const unsigned char& r) { m_r = r; } inline unsigned char RgbColor::G() const { return m_g; } inline void RgbColor::G(const unsigned char& g) { m_g = g; } inline unsigned char RgbColor::B() const { return m_b; } inline void RgbColor::B(const unsigned char& b) { m_b = b; } } } #endif /****************** EOF ******************/ /****************** * ./src/ColorTest.h ******************/ #ifndef STHCOLORTEST_H #define STHCOLORTEST_H #include namespace sth { class ColorTest { public: ColorTest(std::ostream& out); ~ColorTest(); }; }; #endif /****************** EOF ******************/ /****************** * ./src/sth/RgbColor.cpp ******************/ #include "RgbColor.h" namespace sth { util::RgbColor::RgbColor(const unsigned char& r, const unsigned char& g, const unsigned char& b) : m_r(r) , m_g(g) , m_b(b) {} const util::RgbColor util::RgbColor::RED = util::RgbColor(255,0,0); std::ostream& util::RgbColor::print(std::ostream& out) const { out << "util::RgbColor::{r=" << int(this->m_r) << ",g=" << int(this->m_g) << ",b=" << int(this->m_b) << "}\n"; return out; } } /****************** EOF ******************/ /****************** * ./src/main.cpp ******************/ #include "ColorTest.h" #include int main(int argc, char* argv[]) { using sth::ColorTest; ColorTest* ct = new ColorTest(std::cout); } /****************** EOF ******************/ /****************** * ./src/ColorTest.cpp ******************/ #include "ColorTest.h" #include "RgbColor.h" #include namespace sth { ColorTest::ColorTest(std::ostream& out) { util::RgbColor sur(util::RgbColor::RED); out << sur; } ColorTest::~ColorTest() {} }; /****************** EOF ******************/ -- Regards, Steven