Ticket #1929 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

Missing compilation and linking flags on Unix

Reported by: mloskot Owned by: mloskot
Priority: normal Milestone: 1.5.2
Component: ConfigBuild Version: svn-trunk
Severity: normal Keywords: compilation linker cxxflags cflags ldflags
Cc: dron, warmerdam

Description

This is a kind general defect report about dedicated to discussion about missing and incorrect compilation and linking flags in GDAL building system for Unix platforms.

Recently, number of issues have been identified like CXXFLAGS and CFLAGS ignored while building GDAL in debug (CFG=debug) and profiling mode. There are also some flags missing for linker, etc.

Please, include all issues related to this report in comments.

Originally, investigation of this defect has been triggered by Ticket #1927

Attachments

patch Download (366 bytes) - added by kiorky 5 years ago.
patch for LDFLAGS

Change History

Changed 6 years ago by dron

  • cc dron added

Three problems were found during investigating #1927:

1. If compiler flags are being picked up from user input (e.g. using 'CFLAGS="-mtune=v9 -m64" CXXFLAGS="-mtune=v9 -m64" ./configure' command) then they are only used when CFG variable does not contain "debug". For "debug" builds user supplied flags are ignored.

Workaround is to use 'CC="gcc -mtune=v9 -m64" CXX="g++ -mtune=v9 -m64" ./configure', in this case everything is used as it should.

2. Some flags from compilation mode also should be used in linking mode. It seems that GCC (3.3.2 at least) does not understand whether it links 64-bit or 32-bit application without option. AFAIK, Sun linker deduces final format from the format of the first object file. This means we should propagate "-m64" option to linker, LNK_FLAGS can be used here. I am not sure whether it is safe to use CFLAGS contents directly. Probably we should pick up the LDFLAGS variable from user's input and add its contents to LNK_FLAGS.

Current workaround is the the same as in previous case.

3. USER_PREFS variable has a limited usage. It can't be used to switch 32-/64-bit modes, for example, because it comes after configure, and configure script should test compilers, compiler options and external libraries first. USER_PREFS works on make stage and build process can fail because of linking 32-bit library (autodetected by configure) to 64-bit application (enabled later via USER_PREFS).

Best regards, Andrey

Changed 6 years ago by mloskot

  • milestone set to 1.5.0

Changed 5 years ago by mloskot

  • owner changed from warmerdam to mloskot
  • status changed from new to assigned

I fixed the first issue Andrey reported, compilation flags in debug mode (r13129)

Changed 5 years ago by warmerdam

  • cc warmerdam added

r13129 results in default CFLAGS values (ie. -O) leaking into the flags used when CFG=debug.

Since CFG=debug is now partially broken, I'd suggest rushing ahead to strip out the CFG based behavior and go to a more normal CFLAGS/CXXFLAGS based behavior.

Changed 5 years ago by hobu

#2014 is related to this issue.

Changed 5 years ago by hobu

Status on this one? Fixed for 1.5? Needs to be deferred?

Changed 5 years ago by mloskot

I believe it's been mostly fixed. Although I suppose the remaining issue could be that one mentioned above by Andrey about pick up the LDFLAGS variable from user's input and add its contents to LNK_FLAGS. Is that true?

Changed 5 years ago by mloskot

  • status changed from assigned to closed
  • resolution set to fixed

I applied fix for the 2nd issue pointed by Andrey (trunk - r13415 and branches/1.5 - r13416).

Now, GDALmake.opt grabs LDFLAGS from user's input:

export LDFLAGS="..."
./configure

and passes it to linker commands for libgdal and applications.

I also removed duplicated input of libgdal.a from $(GDAL_SLIB) target:

g++ -dynamiclib  /Users/mloskot/dev/gdal/_svn/trunk/gdal/frmts/o/*.o 
...
./ogr/gml2ogrgeometry.o
/Users/mloskot/dev/gdal/_svn/trunk/gdal/libgdal.a
/Users/mloskot/dev/gdal/_svn/trunk/gdal/libgdal.a
  -L/usr/local/lib -lgeos_c -I/usr/include -lsqlite3
  -L/usr/local/lib -lexpat -lNCSEcw -lNCSCnet -lNCSUtil
  -ljasper -ljpeg -lnetcdf -lz  -ldl-L/usr/lib -lcurl -lssl -lcrypto -lz
  -o /Users/mloskot/dev/gdal/_svn/trunk/gdal/libgdal.dylib

I've not added full support of USER_PREFS as, following Andrey's analysis, it has limited usage. So, I assume this issue has been fixed and I'm closing this ticket as fixed. Also, I'm going to close the sister-ticket #1927.

Changed 5 years ago by kiorky

  • status changed from closed to reopened
  • resolution fixed deleted
  • milestone changed from 1.5.1 to 1.4.5

It is not fixed in the 1.4 branch. See the makefile there: http://trac.osgeo.org/gdal/browser/branches/1.4/gdal/GDALmake.opt.in

Changed 5 years ago by kiorky

patch for LDFLAGS

Changed 5 years ago by mloskot

  • owner changed from mloskot to mloskot
  • status changed from reopened to new

Changed 5 years ago by mloskot

  • owner changed from mloskot to mloskot
  • status changed from new to assigned

Changed 5 years ago by mloskot

  • status changed from assigned to closed
  • resolution set to fixed

The LNK_FLAGS has been removed (r13224) and replaced with user space flags LDFLAGS (r13415)

Changed 5 years ago by mloskot

  • milestone changed from 1.4.5 to 1.5.2

Unfortunately, there has been a number of separate commits in trunk that were fixing various compiler and linker flags. I'm sorry, but unable to get the GDALmake.opt and makefile safely synchronized back to branches/1.4. Because these fixes are available in branches/1.5, I'm updating milestone to 1.5.

Note: See TracTickets for help on using tickets.