link error: defined in discarded section

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

do you have built the boost with pgCC or just use pgCC with the gcc’s boost build ?

I have built boost with pgi, but in this case it only includes a header, so there is no need to build boost.

Stefan

boost sometimes will use “auto-link” to do the job, I don’t know whether it exist in your case

I do not know what “auto-link” exactly means. I think that the linker “knows” which boost library is needed. But if a library is missing I would expect an error message like “undefined reference to …”. So I think “auto-link” is not used in this case.

Stefan

Stefan -

This is a linker error that I have not seen before, although it is basically an undefined reference.
First, try to resolve it by linking with the boost library.

If that does not resolve the undefine, then I would like to take a look at it,
if possible.
Please compile Test2.cpp with the flag -Mkeepasm.

Attach test2.s, test2.o and the boost library to a mail message, send it to
trs@pgroup.com , and ask them to pass this directly to me.

  • Deborah Caruso

Stefan -

I’ve reproduced your error here on both the Suse 9.3 and Suse 10.0 linkers.
The error does not occur with the Suse9.1 linker.

There seems to be some incompatibility between our implementation of
.gnu.linkonce sections, and the later Suse linkers. Like gnu, we use
these weak sections to implement templates.

Right now, there is nothing you can do to avoid this error, short of rolling back
to their previous linker.

I have filed this as TPR 4013, So that we can track this bug, and find an
appropriate fix, or possibly file a bug with Suse.