ivansafrin/Polycode — Issue #65: Polycode::Mesh constants cause linker errors when used
Author: mcclure
Created: 2011-12-12 05:45:03+00:00
State: open

I can put this line of code in my program and it builds successfully:

```C++
ScreenMesh *s = new ScreenMesh(Mesh::TRIFAN_MESH);
```

This line of code also builds:

```C++
ScreenMesh *s = (triangle ? new ScreenMesh(Mesh::TRI_MESH) : new ScreenMesh(Mesh::TRIFAN_MESH));
```

This line of code however causes a failure at the link stage:

```C++
ScreenMesh *s = new ScreenMesh(triangle ? Mesh::TRI_MESH : Mesh::TRIFAN_MESH);
```

The linker error:

```C++
"Polycode::Mesh::TRIFAN_MESH", referenced from:
svgloader::loadXml(TiXmlElement*, svgtransform const&) in svgloader.o
"Polycode::Mesh::TRI_MESH", referenced from:
svgloader::loadXml(TiXmlElement*, svgtransform const&) in svgloader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status[/code]
```

I am compiling with XCode 3 on Snow Leopard.

I notice PolyMesh.h defines a bunch of static consts [i]in[/i] the class definition in the header file. Is that altogether legal? Average Software on TIG http://forums.tigsource.com/index.php?topic=1733.msg659828#msg659828 claims:

"It's legal, but if you do anything which requires the constant to actually exist in memory, rather than just be substituted as a compile time constant, the constant must be also defined in a source file somewhere. This is a bug in the library."

I don't know if this is actually something Polycode is doing wrong or just a quirk of my compiler, but if there exist compilers that will treat the code like this, maybe it should not be done this way.

I think there are other source files where this same constant-defined-in-header idiom is used also.