This is the mail archive of the gcc-help@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: pragma in 3.2.x


You must have a corresponding #pragma instruction in you source file as
well...

Add the following line before your #include in PSet.cc

#pragma implementation "PSet.h"

That should fix your problem. 

On Tue, 2002-10-22 at 08:29, Scott A. Smith wrote:
> Greetings,
> 
> I get lots of "undefined reference" errors when linking to my static
> libraries under GCC-3.2. I think I have isolated the problem, it stems from
> #pragma interface in my headers. Here is a simple example:
> 
> ======= PSet.cc
> 
> #include "PSet.h"
> int PSet::Psize() { return size(); }
> 
> ======= PSet.h
> 
> #include <list>
> 
> //#ifdef __GNUG__
> //#pragma interface
> //#endif
> 
> class PSet : public std::list<double> {
>   public:
>   int PSet::Psize();
>   };
> 
> ======= test.cc
> 
> #include <iostream>
> #include "PSet.h"                               // Include our derived list
> 
> int main()
>   {
>   std::cout << std::endl << std::endl;
>   std::cout << "\n\tHello World";
>   PSet ps;
>   std::cout << "\n\tSize is " << ps.Psize();
>   std::cout << std::endl << std::endl;
>   }
> 
> =========================
> 
> If I build a static library containing class PSet with the following:
> 
> g++ -c -I. PSet.cc
> ar r libpset.a PSet.o
> ranlib libpset.a
> 
> and then compile/link/run the "test.cc" program with this
> 
> g++ test.cc -I. -L. -lpset
> ./a.exe
> 
> Everything works fine, BUT if I uncomment the three lines in PSet.h that
> use "pragma interface" I get the following error:
> 
> C:\DOCUME~1\sosi\LOCALS~1\Temp/cce2aaaa.o(.ctors+0x0):test.cc: undefined
> reference to `_GLOBAL__I_main'
> C:\DOCUME~1\sosi\LOCALS~1\Temp/cce2aaaa.o(.dtors+0x0):test.cc: undefined
> reference to `_GLOBAL__D_main'
> 
> This occurs under the latest MinGW (MSYS rxvt shell) where
> 
> gcc -v
> Reading specs from c:/MinGW/bin/../lib/gcc-lib/mingw32/3.2/specs
> Configured with:
> ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --tar
> get=mingw32 --prefix=/mingw
>  --enable-threads --disable-nls --enable-languages=f77,c++,objc,ada --disabl
> e-win32-registry --disable-shared
> Thread model: win32
> gcc version 3.2 (mingw special 20020817-1)
> 
> And occurs under the latest CygWin using gcc 3.2
> 
> Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
> Configured with:
> /netrel/src/gcc-3.2-1/configure --enable-languages=c,c++,f77,java --enable-l
> ibgcj --enable-threads=posi
> x --with-system-zlib --enable-nls --without-included-gettext --enable-interp
> reter --disable-sjlj-exceptions --disable-ve
> rsion-specific-runtime-libs --enable-shared --build=i686-pc-linux --host=i68
> 6-pc-cygwin --target=i686-pc-cygwin --enable
> -haifa --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib 
> --includedir=/nonexistent/include --libexecd
> ir=/usr/sbin
> Thread model: posix
> gcc version 3.2 20020818 (prerelease)
> 
> Can someone tell me what has changed with GCC-3.x that is causing this? Are
> pragmas no longer supported? Does this have to do with template
> instantiation? If so, how can I insure things are instantiated? Do I need
> some
> "external-templates" flag when I invoke the compiler? My project builds and
> links fine under GCC-2.9.x just
> fine, but I get many "undefined reference" errors when linking to its static
> library when everything is compiled under GCC-3.2.x (also on Linux and
> OSX.2)
> 
> Any help appreciated,
> Scott


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