This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fwd: Linking public: static const members in lib*.a's


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 <iostream>
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 <ostream>
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 <iostream>

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 <ostream>

namespace sth
{
  ColorTest::ColorTest(std::ostream& out)
  {
    util::RgbColor sur(util::RgbColor::RED);
    out << sur;
  }
  ColorTest::~ColorTest()
  {}
};
/****************** EOF ******************/



-- 
Regards,
Steven


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]