Bug 215085 - dev-games/ogre - Fix --as-needed with cg
Bug#: 215085 Product:  Gentoo Linux Version: unspecified Platform: All
OS/Version: Linux Status: RESOLVED Severity: normal Priority: P2
Resolution: FIXED Assigned To: games@gentoo.org Reported By: chewi@aura-online.co.uk
Component: Games
URL:  http://www.ogre3d.org
Summary: dev-games/ogre - Fix --as-needed with cg
Keywords:  
Status Whiteboard: 
Opened: 2008-03-27 17:43 0000
Description:   Opened: 2008-03-27 17:43 0000
Because of the way NVIDIA linked their Cg toolkit, building Ogre with the cg
USE flag enabled and -Wl,--as-needed in your LDFLAGS doesn't work. Here's a new
ebuild that filters the flags.

------- Comment #1 From James Le Cuirot 2008-03-27 17:44:29 0000 -------
Created an attachment (id=147461) [details]
ogre-1.4.7.ebuild

Probably no point in incrementing the revision number.

------- Comment #2 From Mr. Bones. 2008-04-08 16:47:40 0000 -------
in portage.  thanks for the bug report and patch.

------- Comment #3 From Sander Sweers 2008-04-08 17:00:42 0000 -------
Filtering --as-needed is just hiding a bug. It should either be left open or
fixed.

------- Comment #4 From Mr. Bones. 2008-04-08 17:04:37 0000 -------
talk is cheap - patches welcome.

------- Comment #5 From James Le Cuirot 2008-04-08 17:24:18 0000 -------
The command that causes the error is...

gcc -o conftest <CFLAGS> -Wl,--as-needed conftest.c -lCg -lILU -lIL -lpthread
-lz -lm -ldl

If you add (or move) -lpthread and -lm before the -Wl,--as-needed option then
it works. Maybe you could do some trick with -Wl,--no-as-needed but you'd have
to make sure that -Wl,--as-needed is added again afterwards and ONLY when it is
wanted. It could be done but it wouldn't be too pretty.

There are two lines in the configure script that add the -lCg option and they
read LIBS="-lCg $LIBS". Maybe something could be done with this.

------- Comment #6 From Sander Sweers 2008-04-08 18:43:22 0000 -------
(In reply to comment #4)
> talk is cheap - patches welcome.

Sigh...

(In reply to comment #5)
> The command that causes the error is...
> 
> gcc -o conftest <CFLAGS> -Wl,--as-needed conftest.c -lCg -lILU -lIL -lpthread
> -lz -lm -ldl
> 
> If you add (or move) -lpthread and -lm before the -Wl,--as-needed option then
> it works. 
> 
> There are two lines in the configure script that add the -lCg option and they
> read LIBS="-lCg $LIBS". Maybe something could be done with this.

Probably changing the linking order from LIBS="-lCg $LIBS" to LIBS="$LIBS -lCg"
will fix it. But I am not able to test that for another week. Could you have a
go at it?

------- Comment #7 From James Le Cuirot 2008-04-08 19:12:36 0000 -------
I tried putting -lCg in various places before but that didn't work. It makes
sense that you have to move -lm and -lpthread because Cg doesn't reference them
when it should and so they must be linked regardless of whether they appear to
be needed.

------- Comment #8 From James Le Cuirot 2008-04-09 17:16:58 0000 -------
Created an attachment (id=149213) [details]
ogre-1.4.7-as-needed.patch

Okay I've come up with a very simple patch. We can get away with only modifying
the configure test because libm and libpthread are actually "needed" by OGRE
itself any other time that libCg is linked. Thanks to the way AC_CHECK_LIB
works, it is easy to add extra arguments to the test. Apply this patch before
the ce-gui patch. "-Xlinker --no-as-needed" was used rather than
"-Wl,--no-as-needed" because the comma confuses autoconf. Sorry for the extra
work, Mr Bones!