Hi,
I’m using the pgi (6.2-5, 64-Bit) compiler together with boost (1.33.1) on an Opteron workstation running OpenSuSE 10.1. I have made the following small example, which works with gcc (4.1.0) but not with pgi:
main.cpp:
#include "Test1.h"
#include "Test2.h"
#include <iostream>
int main()
{
Test1 t;
std::cout << t.foo(11) << std::endl;
}
Test1.h:
#include <string>
class Test1
{
public:
std::string foo(unsigned int t);
};
Test1.cpp:
#include "Test1.h"
#include "boost/format.hpp"
std::string Test1::foo(unsigned int _t)
{
return boost::str( boost::format("%u") % _t);
}
Test2.h:
#include <string>
class Test2
{
public:
std::string foo(unsigned int t);
};
Test2.cpp:
#include "Test2.h"
#include "boost/format.hpp"
std::string Test2::foo(unsigned int _t)
{
return boost::str( boost::format("%u") % _t);
}
makefile:
CXX = pgCC
CXXFLAGS = -I/usr/include
Test : Test1.o Test2.o main.o
$(CXX) -o $@ Test1.o Test2.o main.o
%$(objext) : %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $@
Everything compiles but I get the following message during linking and the executable is not build.
pgCC -o Test Test1.o Test2.o main.o
`.gnu.linkonce.t.parse_printf_directive__tm__84_cQ2_3std20char_traits__tm__2_cQ2_3std18allocator__tm__2_cPCcQ2_3std14ctype__tm__2_c__Q3_5boost2io6detailFRZ4ZRCZ4ZPQ4_5boost2io6detail29format_item__tm__10_Z1ZZ2ZZ3ZRCZ5ZUlUc_b' referenced in section `.data' of Test2.o: defined in discarded section `.gnu.linkonce.t.parse_printf_directive__tm__84_cQ2_3std20char_traits__tm__2_cQ2_3std18allocator__tm__2_cPCcQ2_3std14ctype__tm__2_c__Q3_5boost2io6detailFRZ4ZRCZ4ZPQ4_5boost2io6detail29format_item__tm__10_Z1ZZ2ZZ3ZRCZ5ZUlUc_b' of Test2.o
make: *** [Test] Error 2
If I remove Test2 it works. This error occurs if I use boost::format in two or more files.
What does this linking message exactly mean and how can I solve this problem?
Thanks,
Stefan