-
May 15th, 2013, 11:30 PM
#1
Link time errors for static members
Code:
class NavMeshLoader
{
public:
NavMeshLoader()
{
m_navMesh = loadAll("all_tiles_navmesh.bin");
m_navQuery->init(m_navMesh, 2048);
}
public:
dtNavMesh *loadAll(const std::string& path)
{
FILE* fp = fopen(path.c_str(), "rb");
if (!fp) return 0;
// Read header.
NavMeshSetHeader header;
fread(&header, sizeof(NavMeshSetHeader), 1, fp);
if (header.magic != NAVMESHSET_MAGIC)
{
fclose(fp);
return 0;
}
if (header.version != NAVMESHSET_VERSION)
{
fclose(fp);
return 0;
}
dtNavMesh* mesh = dtAllocNavMesh();
if (!mesh)
{
fclose(fp);
return 0;
}
dtStatus status = mesh->init(&header.params);
if (dtStatusFailed(status))
{
fclose(fp);
return 0;
}
// Read tiles.
for (int i = 0; i < header.numTiles; ++i)
{
NavMeshTileHeader tileHeader;
fread(&tileHeader, sizeof(tileHeader), 1, fp);
if (!tileHeader.tileRef || !tileHeader.dataSize)
break;
unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
if (!data) break;
memset(data, 0, tileHeader.dataSize);
fread(data, tileHeader.dataSize, 1, fp);
mesh->addTile(data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0);
}
fclose(fp);
return mesh;
}
private:
// By reference only, no memory consumption
static dtNavMesh *m_navMesh;
static dtNavMeshQuery* m_navQuery;
static dtQueryFilter m_filter;
static dtStatus m_pathFindStatus;
};
Error 3 error LNK2001: unresolved external symbol "private: static class dtNavMesh * NavMeshLoader::m_navMesh" (?m_navMesh@NavMeshLoader@@0PAVdtNavMesh@@A) D:\Jacky\Documents\Visual Studio 2010\Projects\PerfectSim\PerfectSim\PerfectSim\main.obj PerfectSim
Error 2 error LNK2001: unresolved external symbol "private: static class dtNavMeshQuery * NavMeshLoader::m_navQuery" (?m_navQuery@NavMeshLoader@@0PAVdtNavMeshQuery@@A) D:\Jacky\Documents\Visual Studio 2010\Projects\PerfectSim\PerfectSim\PerfectSim\main.obj PerfectSim
-
May 15th, 2013, 11:40 PM
#2
Re: Link time errors for static members
Did you define these static members in exactly one source file?
-
May 16th, 2013, 04:21 AM
#3
Re: Link time errors for static members
Hi laserlight,
I defined these static members in a file called NavMeshLoader.h. Just defined in this file.
Jack
-
May 16th, 2013, 05:14 AM
#4
Re: Link time errors for static members
Originally Posted by lucky6969b
I defined these static members in a file called NavMeshLoader.h. Just defined in this file.
That is wrong because a header could be included in multiple source files, or not at all. My guess is that the latter happened here, hence the linker cannot find the definitions of these static member variables.
-
May 16th, 2013, 05:31 AM
#5
Re: Link time errors for static members
Originally Posted by lucky6969b
Hi laserlight,
I defined these static members in a file called NavMeshLoader.h. Just defined in this file.
Jack
You did not define them. You only declared them.
Now you have to define them. Something like:
Code:
NavMeshLoader::dtNavMeshQuery* m_navQuery = NULL;
NavMeshLoader::dtStatus m_pathFindStatus;
...
and so on.
Usually you do it in some of the implementation (.cpp) files.
See http://www.tutorialspoint.com/cplusp...ic_members.htm
Victor Nijegorodov
-
May 16th, 2013, 10:32 PM
#6
Re: Link time errors for static members
Yes, I just forgot that.
Thanks for refreshing my memory
Jack
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|