All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
cc can't link to static gcc libs w/ alloca(3)
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login |
|
|
cc can't link to static gcc libs w/ alloca(3) - Dec. 30, '05, 12:19:38 PM
|
|
|
breiter
Posts: 338
Joined: Jun. 14, '04,
From: Washington, DC
Status: offline
|
I'm trying to build clamav with cc instead of gcc to open the door for a mixed-mode build in SUA 5.2 so that it would then be possible to link against libclamav from Win32 code and (I think) P/Invoke into libclamav with .NET.
My initial issue was with ./configure failing due to a quirk of handling -l in cc. But I now have a more serious problem when doing a static link to gmp. I built the gmp package with gcc as a static library. It works fine when used with gcc, but with cc I get an unresolved symbol to alloca. I looked at /usr/include/alloca.h and the interesting thing is that it is defined differently for cc and gcc. Is this binary compatible?
What is the solution? I tried building gmp with --disable-alloca which fixes the problem with GMP but it just pushes the issue downhill to zlib. Is there a magic incantation that fixes this alloca export issue or do I need parallel builds of the libraries?
#ifndef _ALLOCA_H_
#define _ALLOCA_H_
/* Provide a meaningful and correct name for alloca
* for both compilers.
*/
#ifdef _MSC_VER
#define alloca(x) _alloca(x)
#endif
#ifdef __GNUC__
#define alloca(x) __builtin_alloca(x)
#endif
#endif // __ALLOCA_H_
Here's how my link step goes bad. (Note that my cc is sitting on my desktop because I was futzing with it to get it to work with ./configure with -lbind in LDFLAGS.)
/bin/sh ../libtool --mode=link /dev/fs/C/Profiles/breiter/Desktop/cc -D_REENTRA
NT -D_ALL_SOURCE -L/usr/local/lib -L/usr/local/ssl/lib -lbind -lsocket -L/
usr/local/lib -o clamscan output.o getopt.o memory.o cfgparser.o misc.o clams
can.o options.o others.o manager.o treewalk.o ../libclamav/libclamav.la
/dev/fs/C/Profiles/breiter/Desktop/cc -D_REENTRANT -D_ALL_SOURCE -o clamscan out
put.o getopt.o memory.o cfgparser.o misc.o clamscan.o options.o others.o manager
.o treewalk.o -L/usr/local/lib -L/usr/local/ssl/lib ../libclamav/.libs/libclama
v.a -lbind -lc -lz -lbz2 /usr/local/lib/libgmp.a -lpthread -lsocket
libgmp.a(tdiv_q.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(gcdext.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(dc_divrem_n.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(mul.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(gcdext.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(mul.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(invert.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(tdiv_qr.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(mul_fft.o) : error LNK2019: unresolved external symbol __alloca referen
ced in function _mpn_fft_fft_sqr
libz.a(gzio.o) : error LNK2019: unresolved external symbol __alloca referenced i
n function _gzprintf
libgmp.a(powm.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(set_str.o) : error LNK2001: unresolved external symbol __alloca
libgmp.a(mul_n.o) : error LNK2001: unresolved external symbol __alloca
clamscan : fatal error LNK1120: 1 unresolved externals
*** Error code 96
Stop.
*** Error code 1
Stop.
*** Error code 1
Or alternatively with a tweaked GMP build that doesn't use alloca, I get the same issue with zlib:
/dev/fs/C/Profiles/breiter/Desktop/cc -D_REENTRANT -D_ALL_SOURCE -o clamscan out
put.o getopt.o memory.o cfgparser.o misc.o clamscan.o options.o others.o manager
.o treewalk.o -L/usr/local/lib -L/usr/local/ssl/lib ../libclamav/.libs/libclama
v.a -lz -lbz2 /usr/local/lib/libgmp.a -lbind -lpthread -lsocket
libz.a(gzio.o) : error LNK2019: unresolved external symbol __alloca referenced i
n function _gzprintf
clamscan : fatal error LNK1120: 1 unresolved externals
*** Error code 96
Stop.
*** Error code 1
Stop.
*** Error code 1
Stop.
|
|
|
RE: cc can't link to static gcc libs w/ alloca(3) - Dec. 30, '05, 7:21:03 PM
|
|
|
markfunk
Posts: 629
Joined: Mar. 31, '03,
Status: offline
|
The problem is that cc/c89 doesn't add the default gcc compiler
support function library to the list of default libraries/object
files it should use when linking applications. This library is:
/opt/gcc.3.3/lib/gcc-lib/i586-pc-interix3/3.3/libgcc.a
You could add this library to your cc command line directly, ie:
quote:
cc -o xapp xapp.o ... -lXext -lX11 \
/opt/gcc.3.3/lib/gcc-lib/i586-pc-interix3/3.3/libgcc.a
OR you could put this library in the /bin/cc and /bin/c89 scripts,
around lines 1166
quote:
... \
$(unixpath2win /opt/gcc.3.3/lib/gcc-lib/i586-pc-interix3/3.3/libgcc.a) \
$DEF_LIBRARIES ...
and add "-lgcc" on line 1160
quote:
# now add the default libraries
set -A cmd ... "-lgcc" "-lpsxdll"
The only potential problem is with the GNU public license.
I don't remember if libgcc.a is excempt from the license or not.
|
|
|
RE: cc can't link to static gcc libs w/ alloca(3) - Jan. 3, '06, 5:26:24 AM
|
|
|
breiter
Posts: 338
Joined: Jun. 14, '04,
From: Washington, DC
Status: offline
|
Brilliant! Thanks, Mark. I wish I had thought of linking to libgcc. It seems almost obvious in retrospect.
Incidentally, there is no problem linking with libgcc, license-wise. There is an exception to the GPL for linking libgcc so that the terms of the GPL do not apply to your resulting excecutable if you link to libgcc.
quote:
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the Free Software Foundation gives you unlimited permission to link the compiled version of this file into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover modification of the file, and distribution when not linked into a combine executable.)
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Otherwise, every binary produced by gcc would be GPLed.
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|