* [d-kernel] --as-needed и оптимизация
@ 2008-09-08 12:38 Eugene Prokopiev
0 siblings, 0 replies; only message in thread
From: Eugene Prokopiev @ 2008-09-08 12:38 UTC (permalink / raw)
To: ALT Linux kernel packages development
2008/9/8, Kirill A. Shutemov <kirill@>:
> On Mon, Sep 08, 2008 at 12:28:54PM +0400, Eugene Prokopiev wrote:
> > 08.09.08, Konstantin A. Lepikhov<lakostis@> написал(а):
> >
> > > > cc -pthread -lm -o io-latency-test io-latency-test.c
> > > > /tmp/.private/enp/cc6mXiyl.o: In function `main':
> > > > io-latency-test.c:(.text+0x93d): undefined reference to `sqrt'
> > > > collect2: выполнение ld завершилось с кодом возврата 1
> > > > make: *** [io-latency-test] Ошибка 1
> > >
> > > --as-needed ;) Библиотеки должны идти после объектных файлов.
> >
> > Так вроде нет никаких дополнительных объектных файлов ...
> >
> > Как должна выглядеть строка? И в чем разница с:
> >
> > > > $ cc -pthread -lm -o test test.c
>
>
> Строка должна выглядить
>
> $ cc -o test test.c -pthread -lm
>
> См. http://www.altlinux.org/UpStream/AsNeeded
Спасибо. Отвечу сам себе на вопрос "в чем разница" - разница в том,
что в следующем коде:
int main()
{
printf("%f\n",sqrt(2));
return 0;
}
gcc соптимизировал sqrt(2) в константу и линковать libm просто не потребовалось:
$ readelf -d test | fgrep '(NEEDED)'
0x00000001 (NEEDED) Shared library: [libc.so.6]
А вот с таким test.c:
$ cat test.c
#include <math.h>
#include <stdio.h>
#include <time.h>
int main()
{
printf("%f\n",sqrt(time(0)));
return 0;
}
мы получим искомое:
$ cc -pthread -lm -o test test.c
/tmp/.private/enp/cc4uCpp7.o: In function `main':
test.c:(.text+0x4a): undefined reference to `sqrt'
collect2: выполнение ld завершилось с кодом возврата 1
Скомпилировав правильно:
$ cc -o test test.c -pthread -lm
мы увидим, что libm теперь используется:
$ readelf -d test | fgrep '(NEEDED)'
0x00000001 (NEEDED) Shared library: [libm.so.6]
0x00000001 (NEEDED) Shared library: [libc.so.6]
--
С уважением,
Прокопьев Евгений
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-09-08 12:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-08 12:38 [d-kernel] --as-needed и оптимизация Eugene Prokopiev
ALT Linux kernel packages development
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel-kernel/0 devel-kernel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel-kernel devel-kernel/ http://lore.altlinux.org/devel-kernel \
devel-kernel@altlinux.org devel-kernel@altlinux.ru devel-kernel@altlinux.com
public-inbox-index devel-kernel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel-kernel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git