Help with explicit template instantiation, PR#9499

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
bensay
Posts: 202
Joined: Wed Dec 22, 2021 8:14 pm
Location: Danmark
Contact:

Help with explicit template instantiation, PR#9499

Post by bensay »

For TechDraw PR, I have made lots of new templates, that need explicit template instantiation. Developing on Linux, I have gotten the GNU to eat my code, while compiling on Windows are still failing according to CI.

Do we have any Windows developers wanting to help out with those explicit template instantiation? It's an easy task and you don't need any prior experience with FreeCAD code!
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Help with explicit template instantiation, PR#9499

Post by wandererfan »

bensay wrote: Mon May 22, 2023 7:51 pm
I'm no help at all with the Windows aspect. Do you have a code fragment and error message to share? Maybe it will ring a bell for somebody.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Help with explicit template instantiation, PR#9499

Post by wmayer »

https://github.com/FreeCAD/FreeCAD/blob ... ension.cpp

For TechDrawGui the linker fails to get the symbols and the compiler cannot re-create them because the code is in the source files. For the explicit template specialization you have to use the export macro to export the symbols to the library.

For example:

Code: Select all

TechDrawExport template std::string CosmeticExtension::addCosmetic<CosmeticEdge>(BaseGeomPtr bg);
User avatar
bensay
Posts: 202
Joined: Wed Dec 22, 2021 8:14 pm
Location: Danmark
Contact:

Re: Help with explicit template instantiation, PR#9499

Post by bensay »

wmayer wrote: Wed May 24, 2023 9:15 am For TechDrawGui the linker fails to get the symbols and the compiler cannot re-create them because the code is in the source files. For the explicit template specialization you have to use the export macro to export the symbols to the library.

For example:

Code: Select all

TechDrawExport template std::string CosmeticExtension::addCosmetic<CosmeticEdge>(BaseGeomPtr bg);
I tried with

Code: Select all

TechDrawExport template std::string CosmeticExtension::addCosmetic<GeomFormat>(GeomFormat* cosmetic);  // Compiler error
template TechDrawExport std::string CosmeticExtension::addCosmetic<GeomFormat>(GeomFormat* cosmetic);  // Linker error
:(
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Help with explicit template instantiation, PR#9499

Post by wmayer »

Sorry, I wasn't around in the forum in the last five weeks but it looks you got https://github.com/FreeCAD/FreeCAD/pull/9499 working now, right?
User avatar
bensay
Posts: 202
Joined: Wed Dec 22, 2021 8:14 pm
Location: Danmark
Contact:

Re: Help with explicit template instantiation, PR#9499

Post by bensay »

wmayer wrote: Fri Jul 07, 2023 8:04 am Sorry, I wasn't around in the forum in the last five weeks but it looks you got https://github.com/FreeCAD/FreeCAD/pull/9499 working now, right?
Yes, what you sent actually worked. Probably did a typo and then mistakingly concluded it didn't work.
Post Reply