[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Library won't link



On 2020-11-22 11:29 +0200, Wouter Verhelst wrote:

> For the past year, I've been (on and off) working with ola upstream on
> getting new-gcc (first 9, then 10) and python3 issues resolved, so that
> I would be able to get it into bullseye again. We're almost there,
> except for one thing that mystifies me.
>
> As part of the autopkgtest, I build a small program that initializes
> libola to make sure that a basic initialization works. This worked
> previously, but now fails with:
>
> autopkgtest [15:27:45]: test command6:  - - - - - - - - - - stderr - - - - - - - - - -
> /usr/bin/ld: /tmp/cczs0VkU.o: warning: relocation against
> `_ZTVN3ola2io18LoopbackDescriptorE' in read-only section
> `.text._ZN3ola2io18LoopbackDescriptorD2Ev[_ZN3ola2io18LoopbackDescriptorD5Ev]'
> /usr/bin/ld: /tmp/cczs0VkU.o: in function `main':
> hw.cc:(.text+0x11): undefined reference to `ola::io::LoopbackDescriptor::LoopbackDescriptor()'
> /usr/bin/ld: hw.cc:(.text+0x24): undefined reference to `ola::client::OlaClient::OlaClient(ola::io::ConnectedDescriptor*)'
> /usr/bin/ld: hw.cc:(.text+0x30): undefined reference to `ola::client::OlaClient::Setup()'
> /usr/bin/ld: hw.cc:(.text+0xc1): undefined reference to `ola::client::OlaClient::~OlaClient()'
> /usr/bin/ld: hw.cc:(.text+0xe0): undefined reference to `ola::client::OlaClient::~OlaClient()'
> /usr/bin/ld: /tmp/cczs0VkU.o: in function `ola::io::BidirectionalFileDescriptor::~BidirectionalFileDescriptor()':
> hw.cc:(.text._ZN3ola2io27BidirectionalFileDescriptorD2Ev[_ZN3ola2io27BidirectionalFileDescriptorD5Ev]+0xf):
> undefined reference to `vtable for
> ola::io::BidirectionalFileDescriptor'
> /usr/bin/ld:
> hw.cc:(.text._ZN3ola2io27BidirectionalFileDescriptorD2Ev[_ZN3ola2io27BidirectionalFileDescriptorD5Ev]+0x1d):
> undefined reference to `vtable for
> ola::io::BidirectionalFileDescriptor'
> /usr/bin/ld: /tmp/cczs0VkU.o: in function `ola::io::ConnectedDescriptor::~ConnectedDescriptor()':
> hw.cc:(.text._ZN3ola2io19ConnectedDescriptorD2Ev[_ZN3ola2io19ConnectedDescriptorD5Ev]+0xf):
> undefined reference to `vtable for ola::io::ConnectedDescriptor'
> /usr/bin/ld:
> hw.cc:(.text._ZN3ola2io19ConnectedDescriptorD2Ev[_ZN3ola2io19ConnectedDescriptorD5Ev]+0x1d):
> undefined reference to `vtable for ola::io::ConnectedDescriptor'
> /usr/bin/ld: /tmp/cczs0VkU.o: in function `ola::io::LoopbackDescriptor::~LoopbackDescriptor()':
> hw.cc:(.text._ZN3ola2io18LoopbackDescriptorD2Ev[_ZN3ola2io18LoopbackDescriptorD5Ev]+0xf):
> undefined reference to `vtable for ola::io::LoopbackDescriptor'
> /usr/bin/ld:
> hw.cc:(.text._ZN3ola2io18LoopbackDescriptorD2Ev[_ZN3ola2io18LoopbackDescriptorD5Ev]+0x1d):
> undefined reference to `vtable for ola::io::LoopbackDescriptor'
> /usr/bin/ld:
> hw.cc:(.text._ZN3ola2io18LoopbackDescriptorD2Ev[_ZN3ola2io18LoopbackDescriptorD5Ev]+0x31):
> undefined reference to `ola::io::LoopbackDescriptor::Close()'
> /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
> collect2: error: ld returned 1 exit status
> autopkgtest [15:27:45]: @@@@@@@@@@@@@@@@@@@@ summary
>
> (as observed on
> https://salsa.debian.org/wouter/ola/-/jobs/1173462#L1297)
>
>>From what I can make out, the first message happens when a file is
> compiled without -fPIC and then linked into a shared library. This would
> be surprising if that is the reason, for libola is built using libtool
> throughout, and trying the build on stable works with no problem
> whatsoever.
>
> What am I missing?

I think this happens because g++ passes --as-needed to the linker in
unstable, but not in stable.  Your test program is compiled with

g++ -o linktest $(pkg-config --cflags --libs libola) debian/tests/hw.cc

and that adds -lola at the wrong place in the commandline.  According to
the binutils documentation, --as-needed has this effect:

,----
| Object files or libraries appearing on the command line _after_ the
| library in question do not affect whether the library is seen as needed.
| This is similar to the rules for extraction of object files from
| archives.  '--no-as-needed' restores the default behaviour.
`----

So,

g++ -o linktest debian/tests/hw.cc $(pkg-config --cflags --libs libola)

is probably you want instead.

HTH,
    Sven


Reply to: