Re: Make mjpegtools build with LDFLAGS=-Wl, -z, defs

"Steven M. Schultz" <[email protected]> Fri, 28 Mar 2008 11:22:00 -0700 (PDT)
Newsgroups gmane.comp.video.mjpeg.devel
Message-ID <[email protected]>
On Fri, 28 Mar 2008, Fabian Greffrath wrote:

> let's have a look at how 'make' is failing in mpeg2enc/ if ./configure 
> has been run with LDFLAGS="-Wl, -z, defs":

	But now you've change the scenario!  Before you were talking about
	"as needed" linking.  NOW you're talking about "disallowing undefined
	symbols in object files".

	Two completely different things!

>   g++ -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I../utils -march=athlon-4 
> -mno-sse2 -mtune=athlon-4 -Wall -g -O2 -pthread -MT seqencoder.lo -MD 
> -MP -MF .deps/seqencoder.Tpo -c seqencoder.cc -o seqencoder.o 
>  >/dev/null 2>&1

	Right, with <pthreads.h> in scope and -pthread being used the COMPILER
	will happily compile .c or .cpp to .o files WITH UNDEFINED SYMBOLS
	for the pthreads* routines.

	That's good and what is expected.

> 
> /bin/sh ../libtool --tag=CXX --mode=link g++  -march=athlon-4 
> -mno-sse2 -mtune=athlon-4 -Wall -g -O2 -pthread   -Wl,-z,defs -o 
> libmpeg2encpp.la -rpath /usr/local/lib  -version-info 1:1:1 -release ...
> 
> -march=athlon-4 -mno-sse2 -mtune=athlon-4 -pthread -Wl,-z -Wl,defs 
> -Wl,-soname -Wl,libmpeg2encpp-1.9.so.0 -o .libs/libmpeg2encpp-1.9.so.0.1.1
> .libs/seqencoder.o: In function `Despatcher::Init(unsigned int)':
> /home/fabian/temp/mjpegtools-1.9.0rc3/mpeg2enc/seqencoder.cc:144: 
> undefined reference to `pthread_attr_getstacksize'
> /home/fabian/temp/mjpegtools-1.9.0rc3/mpeg2enc/seqencoder.cc:159: 
> undefined reference to `pthread_create'
> /home/fabian/temp/mjpegtools-1.9.0rc3/mpeg2enc/seqencoder.cc:148: 
> undefined reference to `pthread_attr_setstacksize'
> .libs/seqencoder.o: In function `~Despatcher':
> /home/fabian/temp/mjpegtools-1.9.0rc3/mpeg2enc/seqencoder.cc:183: 
> undefined reference to `pthread_join'
> /home/fabian/temp/mjpegtools-1.9.0rc3/mpeg2enc/seqencoder.cc:183: 
> undefined reference to `pthread_join'
> collect2: ld returned 1 exit status
> make: *** [libmpeg2encpp.la] Error 1

> In the second section you can see the linker fail to resolve 
> references to the pthread_* symbols in this very object.

	The LINKER (not the compiler) is, I think, only doing exactly
	what you told it to do.

	You specified "-Wl, -z, defs" which says (I finally found a system
	which had a manpage that had '-z' mentioned):

       -z keyword
           The recognized keywords are:

           defs
               Disallows undefined symbols in object files.  Undefined symbols
               in shared libraries are still allowed.

	"-z defs" means, to me, that .o files are not allowed to have
	undefined symbols.   

> The funny thing is, if I reset LDFLAGS empty in Makefile and run 
> 'make' again, compilation succeeds and the resulting 

	Right, If you do NOT specify the "complain about .o files which
	have undefined symbols" option then  the linking will work.

	That doesn't seem too surprising to me :-)

> .libs/libmpeg2encpp.so *is* linked against libpthread.so.0.
> 
> Strange, isn't it?

	Not at all.  If I tell the linker "do not allow undefined symbols"
	then I really shouldn't find it strange that the linker gives me
	errors.  

	It's somewhat like the joke:

	Patient:  Doctor, it hurts when I hit my head on the wall.
	Doctor:  Well, don't do that :)

	Cheers,
	Steven Schultz


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace