Project

General

Profile

Design #1019

CPP flags in installed library

Added by John Abbott over 7 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Portability
Start date:
05 Mar 2017
Due date:
% Done:

100%

Estimated time:
7.70 h
Spent time:

Description

What is the best way to ensure that any important CPP flags are correctly set when using CoCoALib?

One approach is given in #1015 where there is a link-time check.

Another possibility would be to have a header file which explcitly sets the flags to the right values.

Discuss!


Related issues

Related to CoCoALib - Bug #1015: Bruns SEGV: SparsePolyIter/DMPI problemClosed2017-03-01

Related to CoCoALib - Feature #1050: ExternalLibs: function for getting infoClosed2017-04-24

History

#1 Updated by John Abbott over 7 years ago

  • Related to Bug #1015: Bruns SEGV: SparsePolyIter/DMPI problem added

#2 Updated by John Abbott over 7 years ago

  • Description updated (diff)
  • Status changed from New to In Progress
  • % Done changed from 0 to 10

Recently Bruns reported a compilation problem (see #1015) which turned out to be a problem of missing CPP flags. A solution was proposed in #1015:

  • (A) use some "trickery" to check that the correct CPP flags have been specified when compiling an application using CoCoALib. Any problems will be reported at link-time.

Now I have thought of an alternative approach:

  • (B) add a new header file (created by the configure script) which forcibly sets the correct values for the relevant CPP flags.

The main difference between (A) and (B) from the point of view of an application programmer is that with (A) some CoCoALib flags must be specified with every compilation that depends on CoCoALib (header) files, whereas with approach (B) there is no need to specify these flags.

I note that the GMP header file does include several #define directives, so conclude that it is "acceptable practice".

#3 Updated by John Abbott over 7 years ago

To me it seems that approach (A) is less convenient and more risky/annoying (since any problem is reported only after compilation has finished).

Approach (B) would appear to have all the advantages (except that I have to implement it, while I have just finished implementing (A)... sigh!)

Can anyone see any potential problems with approach (B)?

NOTE: The CPP flags should be set before any of the existing header files is read. This could be done by putting them in the "preamble" of the unified header file". Having the #define directives at the very start means that any values supplied as part of the compilation command will effectively be ignored. Is this OK? One could argue that an external user should not "mess about with" the CoCoALib CPP flags. If necessary, I could add a check that the flags have not been defined.

#4 Updated by John Abbott over 7 years ago

Here is a list of the CoCoA CPP flags:
  • CoCoA_ULONG2LONG
  • CoCoA_THREADSAFE_HACK
  • CoCoA_DEBUG
  • CoCoA_MEMPOOL_DEBUG
  • CoCoA_WITH_BOOST
  • CoCoA_WITH_READLINE
  • CoCoA_WITH_NORMALIZ
  • CoCoA_WITH_CDD
  • CoCoA_WITH_FROBBY
  • CoCoA_WITH_GFAN
  • CoCoA_WITH_GSL
  • CoCoA_WITH_MATHSAT

All settings referring to external libs have to ensure that appropriate flags are given to the linker!

Currently, if CoCoA_WITH_NORMALIZ is set then also the compilation option -Wno-long-long is set.

Currently, CoCoA_WITH_CDD and CoCoA_WITH_FROBBY are either both set or both unset.

#5 Updated by John Abbott over 7 years ago

  • Assignee set to John Abbott

#6 Updated by John Abbott over 7 years ago

NOTE I have just learned that if you press return while typing in the comment "subject" line, redmine then "finishes" the update (without giving you the chance to type in more details).

The flag CoCoA_WITH_READLINE is a red-herring: it applies only to CoCoA-5, and so should not really appear among the CoCoALib CPP flags.

Our handling (so far) of the flags CoCoA_DEBUG and CoCoA_MEMPOOL_DEBUG has been special: the options could be activated/deactivated by simply editing part of autoconf.mk and then recompiling -- Makefile dependencies are such that changing autoconf.mk triggers recompilation. Personally I find this approach convenient. I believe Anna has two separate subtrees, one for "optimized" CoCoALib, and one for "debugging" CoCoALib.

Up to now I have assumed that an installed version of CoCoALib would be an "optimized" version. Since CoCoALib is distributed as source code, I think it is reasonable to suppose that a person wishing to use CoCoALib with debugging active would have a private copy of CoCoALib (which can be configured as desired). Do you think this is reasonable?

#7 Updated by John Abbott over 7 years ago

  • % Done changed from 10 to 20

After some consideration I think it is best to put all the CPP "flags" into a single header file, then any files which depend directly on one or more such flags must include that header file.

I had also considered having several different files, but see no advantage to doing so (and suspect that it could easily become cumbersome and hard to comprehend).

I hope to make a trial implementation soon.

#8 Updated by John Abbott over 7 years ago

I now have a first impl of the "preprocessor definitions" header file.

One question which has just arisen is the following:
in files such as ExternalLib-Normaliz.C there are two ways of achieving the effect of "compile only if CoCoA_WITH_NORMALIZ is defined"

Method (1)

#include "CoCoA/PREPROCESSOR_DEFNS.H" 
#ifdef CoCoA_WITH_NORMALIZ
...
#endif

Method (2)

// Copyright blah blah
// ..

#include "CoCoA/ExternalLibs-Normaliz.H" 
#ifdef CoCoA_WITH_NORMALIZ

...
#endif

Method (1) will probably be slightly faster (since the compiler does not have to read in a few lines of comments), but I doubt the difference is noticeable.

Method (2) avoids having to put an explicit #include "CoCoA/PREPROCESSOR_DEFNS.H" directive since it is already read by the header file.

Comments? Preferences?

#9 Updated by John Abbott over 7 years ago

The tests are producing strange results: it seems that there is some mysterious problem with the threadsafe counter :-/

NOTE I had forgotten this problem. Anyway it is now resolved (see #1048): there were some missing include directives in files refering to CoCoA_THREADSAFE_HACK

#10 Updated by John Abbott about 7 years ago

  • Status changed from In Progress to Feedback
  • % Done changed from 20 to 90
  • Estimated time set to 7.70 h

CoCoALib now compiles fine with this new approach to handling CPP flags.

There remains a problem with the way (dodgy hack!) CoCoA-5 determines which external libraries have been included in CoCoALib. Right now, I do not have a good idea to make this work again.

#11 Updated by John Abbott about 7 years ago

  • Target version changed from CoCoALib-0.99560 to CoCoALib-0.99550 spring 2017

Can we close this issue and open a new one about the problem of CoCoA-5 not seeing which external libs are in CoCoALib? Or should this issue also cover the CoCoA-5 problem?

#12 Updated by John Abbott about 7 years ago

  • Related to Feature #1050: ExternalLibs: function for getting info added

#13 Updated by John Abbott about 7 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

I am now sufficiently convinced by the current design that I am closing this issue.
The flags in PREPROCESSOR_DEFNS.H are those directly relevant to CoCoALib;
I am happy to put the flags relating to external libraries elsewhere.

The remaining question (about external libs) has become a new issue (#1050).

Also available in: Atom PDF