[gdal-dev] build system vs. libtool: static libraries must be enabled

Ivan Shmakov ivan at theory.asu.ru
Fri Dec 14 14:22:17 EST 2007


>>>>> Ivan Shmakov <ivan at theory.asu.ru> writes:

[...]

 > IIUC, when using `libtool', the `.o' files are put into the `.libs/'
 > subdirectory, and in the build directory the corresponding `.lo' are
 > created instead.  Thus, Make ends up trying to build each of the `.o'
 > files each time it's run.

	It seems to me that I understand the Libtool logic now.  The
	`.o' files are only built when static libraries are requested,
	and `.lo' (and the corresponding `.libs/.o') files are built
	only when one requests shared ones.

	Hence, as a workaround, I've tried configuring with
	`--enable-static', and it builds without the problem.

	In my opinion, it's a bug in the current GDAL build system.
	Could the #1878 ticket be reopened (with the description changed
	accordingly)?

	The relevant parts of `libtool' are as follows.

...
  2031	# func_mode_compile arg...
  2032	func_mode_compile ()
  2033	{
...
  2141	    # Recognize several different file suffixes.
  2142	    # If the user specifies -o file.o, it is replaced with file.lo
  2143	    xform='[cCFSifmso]'
  2144	    case $libobj in
...
  2153	    *.cpp) xform=cpp ;;
...
  2159	    esac
  2160	
  2161	    libobj=`$ECHO "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"`
  2162	
  2163	    case $libobj in
  2164	    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
  2165	    *)
  2166	      func_fatal_error "cannot determine name of library object from \`$libobj'"
  2167	      ;;
  2168	    esac
...
  2172	    for arg in $later; do
  2173	      case $arg in
  2174	      -shared)
  2175		test "$build_libtool_libs" != yes && \
  2176		  func_fatal_configuration "can not build a shared library"
  2177		build_old_libs=no
  2178		continue
  2179		;;
  2180	
  2181	      -static)
  2182		build_libtool_libs=no
  2183		build_old_libs=yes
  2184		continue
  2185		;;
...
  2196	      esac
  2197	    done
...
  2203	    func_basename "$obj"
  2204	    objname="$func_basename_result"
  2205	    func_dirname "$obj" "/" ""
  2206	    xdir="$func_dirname_result"
  2207	    lobj=${xdir}$objdir/$objname
...
  2212	    # Delete any leftover library objects.
  2213	    if test "$build_old_libs" = yes; then
  2214	      removelist="$obj $lobj $libobj ${libobj}T"
  2215	    else
  2216	      removelist="$lobj $libobj ${libobj}T"
  2217	    fi
  2218	
  2219	    $opt_dry_run || $RM $removelist
  2220	    trap "$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE" 1 2 15
...
  2272	    if test -n "$fix_srcfile_path"; then
  2273	      eval srcfile=\"$fix_srcfile_path\"
  2274	    fi
  2275	    func_quote_for_eval "$srcfile"
  2276	    qsrcfile=$func_quote_for_eval_result
  2277	
  2278	    $opt_dry_run || $RM "$libobj" "${libobj}T"
  2279	
  2280	    # Only build a PIC object if we are building libtool libraries.
  2281	    if test "$build_libtool_libs" = yes; then
...
  2292	      func_mkdir_p "$xdir$objdir"
  2293	
  2294	      if test -z "$output_obj"; then
  2295		# Place PIC objects in $objdir
  2296		command="$command -o $lobj"
  2297	      fi
  2298	
  2299	      $opt_dry_run || $RM "$lobj" "$output_obj"
  2300	
  2301	      func_show_eval "$command"	\
  2302	          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
...
  2324	      # Just move the object if needed, then go on to compile the next one
  2325	      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
  2326		func_show_eval '$MV "$output_obj" "$lobj"' \
  2327		  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
  2328	      fi
  2329	
  2330	      # Allow error messages only from the first compilation.
  2331	      if test "$suppress_opt" = yes; then
  2332		suppress_output=' >/dev/null 2>&1'
  2333	      fi
  2334	    fi
  2335	
  2336	    # Only build a position-dependent object if we build old libraries.
  2337	    if test "$build_old_libs" = yes; then
  2338	      if test "$pic_mode" != yes; then
  2339		# Don't build PIC code
  2340		command="$base_compile $qsrcfile$pie_flag"

	BTW, isn't a whitespace missing here?

  2341	      else
  2342		command="$base_compile $qsrcfile $pic_flag"
  2343	      fi
  2344	      if test "$compiler_c_o" = yes; then
  2345		command="$command -o $obj"
  2346	      fi
  2347	
  2348	      # Suppress compiler output if we already did a PIC compilation.
  2349	      command="$command$suppress_output"
  2350	      $opt_dry_run || $RM "$obj" "$output_obj"
  2351	      func_show_eval "$command" \
  2352	        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
...
  2381	    $opt_dry_run || {
  2382	      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
  2383	
  2384	      # Unlock the critical section if it was locked
  2385	      if test "$need_locks" != no; then
  2386	        $RM "$lockfile"
  2387	      fi
  2388	    }
  2389	
  2390	    exit $EXIT_SUCCESS
  2391	}
  2392	
  2393	test "$mode" = compile && func_mode_compile ${1+"$@"}
...

[...]



More information about the gdal-dev mailing list