This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/26699] New: LD doesn't link in an object from an archive when the object has only public variables
- From: "karel at kubat dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Mar 2006 16:13:32 -0000
- Subject: [Bug c/26699] New: LD doesn't link in an object from an archive when the object has only public variables
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Bug description: An object that has only public variables is placed in an
archive. Linking against that archive fails: probably ld doesn't link in the .o
from the archive because it contains only public variables.
gcc -v output: Reading specs from
/usr/lib/gcc/powerpc-apple-darwin8/4.0.0/specs
Configured with: /private/var/tmp/gcc/gcc-4061.obj~8/src/configure
--disable-checking --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^+.-]*$/s/$/-4.0/
--with-gxx-include-dir=/include/gcc/darwin/4.0/c++
--build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8
--target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.0 20041026 (Apple Computer, Inc. build 4061)
Problem description:
I create a file "data.c" with herein a variable definition:
int winner = 666;
I compile data.c into data.o (gcc -c -o data.o data.c) and add it to libdata.a
using
ar rs libdata.a data.o
ranlib libdata.a
Now I compile a program that accesses the variable winner, e.g. the following
main.c:
#include <stdio.h>
extern int winner;
int main () {
printf ("The winner is %d\n", winner);
return (0);
}
The compilation / linkage:
cc -o main.o main.c
cc -o main -L. -ldata main.o
BUG: ld won't select data.o out of libdata.a to link with main.o. There's an
unresolved reference to _winner.
--
Summary: LD doesn't link in an object from an archive when the
object has only public variables
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: karel at kubat dot nl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26699