From owner-freebsd-questions@FreeBSD.ORG Thu Nov 29 20:54:04 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EA2D779F for ; Thu, 29 Nov 2012 20:54:04 +0000 (UTC) (envelope-from freebsd@dreamchaser.org) Received: from nightmare.dreamchaser.org (nightmare.dreamchaser.org [12.32.44.142]) by mx1.freebsd.org (Postfix) with ESMTP id A81B98FC08 for ; Thu, 29 Nov 2012 20:54:04 +0000 (UTC) Received: from breakaway.dreamchaser.org (breakaway.dreamchaser.org. [12.32.36.73]) by nightmare.dreamchaser.org (8.13.6/8.13.6) with ESMTP id qATKs2xh094125 for ; Thu, 29 Nov 2012 13:54:03 -0700 (MST) (envelope-from freebsd@dreamchaser.org) Message-ID: <50B7CB6A.2060606@dreamchaser.org> Date: Thu, 29 Nov 2012 13:54:02 -0700 From: Gary Aitken User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:16.0) Gecko/20121116 Thunderbird/16.0.2 MIME-Version: 1.0 To: FreeBSD Mailing List Subject: ld; extracting from libraries; and related questions Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (nightmare.dreamchaser.org [12.32.36.65]); Thu, 29 Nov 2012 13:54:03 -0700 (MST) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: freebsd@dreamchaser.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2012 20:54:05 -0000 I'm trying to track down why a library I've built doesn't have the stuff it's supposed to. The .o files are from a more recent port of glib, built in a non-standard place; but the .so contains files which appear to be from the standard /usr/ports installation. Something strange happened when building the lib. Using objdump I can see that the .o contains the correct version. Is it possible to extract a .o from a lib.a or lib.so, so I can compare it to the .o built by the make? Initially, I was testing via a C program that dumps out glib_major_version, glib_minor_version, and glib_micro_version In order to narrow this down, I ended up having to link as follows: ld -o a.out /usr/lib/crt1.o garya.o \ ~/.../ports/devel/glib20/work/glib-2.34.1/glib/gversion.o \ ~/.../ports/devel/glib20/work/glib-2.34.1/glib/.libs/libglib-2.0.so.0 \ -lc When the above linked a.out runs, I see the correct value (2.34.1) When gversion.o is left out of the link, I see the incorrect version (2.28.8) If I link with gversion.o and -lc only, I have unresolved symbols from crt1.o: /usr/lib/crt1.o: In function `_start': crt1.c:(.text+0x73): undefined reference to `_fini' crt1.c:(.text+0x7d): undefined reference to `_init' where should they come from? I thought maybe I should be using crt0.o but I don't see one anywhere. If I try adding in /usr/lib/crti.o, which resolves the missing symbols, I get a segv before even entering main. I also thought the .a was simply a static version of the .so, but that doesn't appear to be the case, since linking with the .a still has the unresolved symbols. I haven't done this for a *long* while so I'm pretty out of date. Any clarifications would be much appreciated. Thanks, Gary