Re: inconsistent library link

Bram Moolenaar <[email protected]> Fri, 06 Feb 2004 13:41:53 +0100
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
Mathew Boorman wrote:

> The following log is for 2 attempts to build a shared lib and an
> application linked against it.
> 
> The first time it tries to link the lib with g++, which fails.
> Building again and it links the lib with ld -shared which works fine.
> 
> [[email protected] aap]$ aap
> Aap:  g++       -MM dog.cpp > build-Linux2_4_20_8/dog.cpp.aap
> Aap: g++    -O2  -fPIC -c -o build-Linux2_4_20_8/dog.sho dog.cpp
> Aap: g++  -O2 -o libdog.so build-Linux2_4_20_8/dog.sho
> /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x18): In
> function `_start':
> ../sysdeps/i386/elf/start.S:77: undefined reference to `main'
> collect2: ld returned 1 exit status
> Aap: Error in recipe "/home/mat/aap/main.aap" line 5: Error executing
> commands for builddll default: Error in recipe
> "/usr/local/lib/aap/Exec-1.049/default.aap" line 493: Error executing
> commands for cxx_build default: Error in recipe
> "/usr/local/lib/aap/Exec-1.049/default.aap" line 427: Shell command
> returned 1
> 
> 
> [[email protected] aap]$ aap
> Aap: ld  -shared -o libdog.so build-Linux2_4_20_8/dog.sho
> Aap:  g++       -MM go1.cpp > build-Linux2_4_20_8/go1.cpp.aap
> Aap: g++    -O2  -c -o build-Linux2_4_20_8/go1.o go1.cpp
> Aap: g++ -L. -O2 -o go1 build-Linux2_4_20_8/go1.o -ldog
> 
> 
> Rule file was:
> # aap sample
> :dll dog : dog.cpp
> 
> :program go1 
> 	{var_LIBS= -ldog }
> 	{var_LDFLAGS= -L. }
> 	:
>  	go1.cpp

Strange but true, I can reproduce it.

It's actually wrong in both cases: The first one because of the missing
"-shared" argument, the second one because using "ld" for C++ is not
good.

This patch should at least make it work.  It fixes the first problem, so
that we don't run into the second one.  It's not the complete solution,
because the difference between running Aap one time with a failure and
running it again still exists.  I'll put that on my todo list.

*** default.aap~	Wed Oct 29 12:05:51 2003
--- default.aap	Fri Feb  6 13:33:41 2004
***************
*** 264,270 ****
  :action compile dllobject cpp
      @if not _no.get("target"):
  	target = `src2obj(fname, sufname = "DLLOBJSUF")`
!     :attr {buildaction = cxx_build} $target	# Need to build with $CXX
      act = $?CXX_COMPILE_ACTION
      @if not act:
  	act = $?COMPILE_ACTION	    # be backwards compatible
--- 264,270 ----
  :action compile dllobject cpp
      @if not _no.get("target"):
  	target = `src2obj(fname, sufname = "DLLOBJSUF")`
!     :attr {buildaction = cxx_builddll} $target	# Need to build with $CXX
      act = $?CXX_COMPILE_ACTION
      @if not act:
  	act = $?COMPILE_ACTION	    # be backwards compatible
***************
*** 459,464 ****
--- 459,467 ----
  		:do $action {target = $target} $source
  	    @else:
  		:sys $SHLINK $SHLINKFLAGS /OUT:$target $source
+     :action cxx_builddll default
+         # TODO: Is this correct?
+         :do builddll {target = $target} $source
  @else:
      SHLINK ?= ld
      SHLINKFLAGS ?= -shared
***************
*** 474,479 ****
--- 477,490 ----
  		:do $action {target = $target} $source
  	    @else:
  		:sys $SHLINK $LDFLAGS $SHLINKFLAGS -o $target $source
+     CXXSHLINK ?= $CXX
+     CXXSHLINKFLAGS ?= -shared
+     :action cxx_builddll default
+ 	@if _no.get("CXX_BUILDDLL_ACTION"):
+ 	    # Building is handled by a specific tool.
+ 	    :do $CXX_BUILDDLL_ACTION {target = $target} $source
+ 	@else:
+             :sys $CXXSHLINK $LDFLAGS $CXXSHLINKFLAGS -o $target $source
  
  
  # :do email

-- 
hundred-and-one symptoms of being an internet addict:
56. You leave the modem speaker on after connecting because you think it
    sounds like the ocean wind...the perfect soundtrack for "surfing the net".

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn