Skip to content
Snippets Groups Projects
Closed Function1/CSV/CSV.C: Need to move explicit template specializations to a separate file (ex: CSVTemplates.C)
  • View options
  • Function1/CSV/CSV.C: Need to move explicit template specializations to a separate file (ex: CSVTemplates.C)

  • View options
  • Closed Issue created

    Summary

    The file src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C contains 2 explicit template specializations for the member function ::readValue(). Those will be reported as multiply-defined by the linker when the corresponding file CSV.H gets included in the source code of a custom-build library depending on the core library libOpenFOAM.

    Steps to reproduce

    Simply add the statement "#include CSV.H" in the source code of any custom-made library depending on the libOpenFOAM library.

    Since the file CSV.C is included at the bottom of the file CSV.H, the 2 explicit template specializations will be reported as multiply-defined by the linker.

    Example case

    This is a compilation issue.

    What is the current bug behaviour?

    The custom-build library fails to link. An error message is written at the console stating that 2 instances of the template specialized member function ::readValue() are multiply-defined, and are first defined at lines 72 and 82 of src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C

    What is the expected correct behaviour?

    Proper linking of the custom-made library when using the class Foam::Function1Types::CSV.

    Relevant logs and/or images

    Environment information

    • OpenFOAM version : probably all versions of OpenFOAM since the files CSV.[CH] were introduced.
    • Operating system : Fedora 33
    • Hardware info :
    • Compiler : gcc 10.3.1

    Possible fixes

    Move the following 2 explicit template specializations to a separate file like src/OpenFOAM/primitives/functions/Function1/CSV/CSVTemplates.C

    Add the file CSVTemplates.C to the file src/OpenFOAM/Make/files.

    From src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C

         65 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
         66 
         67 template<>
         68 Foam::label Foam::Function1Types::CSV<Foam::label>::readValue
         69 (
         70     const List<string>& strings
         71 ) const
         72 {
         73     return readLabel(strings[componentColumns_[0]]);
         74 }
         75 
         76 
         77 template<>
         78 Foam::scalar Foam::Function1Types::CSV<Foam::scalar>::readValue
         79 (
         80     const List<string>& strings
         81 ) const
         82 {
         83     return readScalar(strings[componentColumns_[0]]);
         84 }
    Edited

    Linked items 0

  • Link items together to show that they're related.

    Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first