简体   繁体   English

解释未解析的外部 C++

[英]Interpreting unresolved externals C++

I'm having a go at making a minecraft renderer.我在制作我的世界渲染器时有一个 go。 When loading the world from the region files, it stores the parsed NBT data in an unordered map, with the nbt data as the value and the global chunk coordinates as the key.从区域文件加载世界时,它将解析的 NBT 数据存储在无序的 map 中,其中 nbt 数据作为值,全局块坐标作为键。 Specifically unordered_map<pair<int, int>, CompoundTag*> (the compound tag being the NBT data)特别unordered_map<pair<int, int>, CompoundTag*> (复合标签是 NBT 数据)

However, I'm running into a compile time error that seems to point at the unordered map.但是,我遇到了似乎指向无序 map 的编译时错误。 It is as follows.如下。

Error LNK2001 unresolved external symbol "class std::unordered_map,struct Chunk,struct std::hash >,struct std::equal_to >,class std::allocator const,struct Chunk> > > __cdecl createChunks(class std::unordered_map,class CompoundTag,struct std::hash >,struct std::equal_to >,class std::allocator const,class CompoundTag> > > &,class Asset &)" (?createChunks@@YA?AV?$unordered_map@U?$pair@HH@std@@UChunk@@U?$hash@U?$pair@HH@std@@@2@U?$equal_to@U?$pair@HH@std@@@2@V?$allocator@U?$pair@$$CBU?$pair@HH@std@@UChunk@@@std@@@2@@std@@AEAV?$unordered_map@U?$pair@HH@std@@VCompoundTag@@U?$hash@U?$pair@HH@std@@@2@U?$equal_to@U?$pair@HH@std@@@2@V?$allocator@U?$pair@$$CBU?$pair@HH@std@@VCompoundTag@@@std@@@2@@2@AEAVAsset@@@Z)错误 LNK2001 未解析的外部符号“类 std::unordered_map,struct Chunk,struct std::hash >,struct std::equal_to >,class std::allocator const,struct Chunk> >: class CompoundTag,struct std::hash >,struct std::equal_to >,class std::allocator const,class CompoundTag> > > &,class Asset &)" (?createChunks@@YA?AV?$unordered_map@U? $pair@HH@std@@UChunk@@U?$hash@U?$pair@HH@std@@@2@U?$equal_to@U?$pair@HH@std@@@2@V?$分配器@U?$pair@$$CBU?$pair@HH@std@@UChunk@@@std@@@2@@std@@AEAV?$unordered_map@U?$pair@HH@std@@VCompoundTag@ @U?$hash@U?$pair@HH@std@@@2@U?$equal_to@U?$pair@HH@std@@@2@V?$allocator@U?$pair@$$CBU ?$pair@HH@std@@VCompoundTag@@@std@@@2@@2@AEAVAsset@@@Z)

I've solved unresolved externals before, and usually it's because I forgot to include an external file (hence the name) that the program needs.我以前解决过未解决的外部问题,通常是因为我忘记包含程序需要的外部文件(因此得名)。 However, this time I'm fairly certain I have everything it needs.然而,这一次我相当肯定我拥有它需要的一切。 I've included unordered_map at the top of the of the file.我在文件顶部包含了 unordered_map。 I've included the header where Chunk is defined, and I'm aware of the need for the custom build hash and equal_to functions, and provided them with the following in a header file that is included.我已经包含了定义 Chunk 的 header,并且我知道需要自定义构建 hash 和 equal_to 函数,并在 Z099FB995346F31C749F6E40E40DB0F 文件中为它们提供了以下内容。

namespace std
{
    template<>
    struct hash<pair<int32_t, int32_t>>
    {
        size_t operator ()(const pair<int32_t, int32_t>& value) const
        {
            uint64_t key = ((uint64_t)value.first) << 32 | (uint64_t)value.second;
            key ^= (key >> 33);
            key *= 0xff51afd7ed558ccd;
            key ^= (key >> 33);
            key *= 0xc4ceb9fe1a85ec53;
            key ^= (key >> 33);
            return (size_t)key;
        }
    };


    template<>
    struct equal_to<pair<int32_t, int32_t>>
    {
        bool operator ()(const pair<int32_t, int32_t>& v1, const pair<int32_t, int32_t>& v2) const
        {
            return (v1.first == v2.first) && (v1.second == v2.second);
        }
    };
}

The only other thing I thought I might need to do is provide a custom allocator?我认为我可能需要做的唯一另一件事是提供自定义分配器? But everything I found about using pairs as keys in unordered_maps says that it's not necessary.但是我发现关于在 unordered_maps 中使用对作为键的所有内容都表明这是没有必要的。 I'm a little stumped, and would be grateful for any insight.我有点难过,如果有任何见解,我将不胜感激。 If you have any questions or want to see more of the code please ask.如果您有任何问题或想查看更多代码,请询问。 It's on my github if you want to look at the project as a whole, but if you (justifiably) don't want to sort through that whole mess please just ask for clarification on anything or extra information.如果您想从整体上查看项目,它在我的github上,但如果您(有理由)不想整理整个混乱,请要求澄清任何事情或额外信息。

Edit 1, I parsed the error the best I can.编辑 1,我尽我所能解析错误。

class std::unordered_map
<
    struct std::pair
    <
        int,
        int
    >,
    struct Chunk *,
    struct std::hash
    <
        struct std::pair
        <
            int,
            int
        > 
    >,
    struct std::equal_to
    <
        struct std::pair
        <
            int,
            int
        >
    >,
    class std::allocator
    <
        struct std::pair
        <
            struct std::pair
            <
                int,int
            > const,
            struct Chunk *
        > 
    > 
>

__cdecl createChunks(
    class std::unordered_map
    <
        struct std::pair
        <
            int,
            int
        >,
        class CompoundTag *,
        struct std::hash
        <
            struct std::pair
            <
                int,
                int
            >
        >,
        struct std::equal_to
        <
            struct std::pair
            <
                int,
                int
            >
        >,
        class std::allocator
        <
            struct std::pair
            <
                struct std::pair
                <
                    int,
                    int
                > const,
                class CompoundTag *
            > 
        > 
    >&
    ,class Asset&
) 


(?createChunks@@YA?AV?$unordered_map@U?$pair@HH@std@@PEAUChunk@@U?$hash@U?$pair@HH@std@@@2@U?$equal_to@U?$pair@HH@std@@@2@V?$allocator@U?$pair@$$CBU?$pair@HH@std@@PEAUChunk@@@std@@@2@@std@@AEAV?$unordered_map@U?$pair@HH@std@@PEAVCompoundTag@@U?$hash@U?$pair@HH@std@@@2@U?$equal_to@U?$pair@HH@std@@@2@V?$allocator@U?$pair@$$CBU?$pair@HH@std@@PEAVCompoundTag@@@std@@@2@@2@AEAVAsset@@@Z)    MCRenderer  C:\Users\noahm\source\repos\noahwhygodwhy\MCRenderer\MCRenderer\MCRenderer.obj  1   

The error message is long, but if you read it carefully it's referring to a missing function called createChunks .错误消息很长,但如果您仔细阅读,它指的是缺少的 function 称为createChunks

The unordered_map is simply the return type (and parameter type) of that function. unordered_map 只是 function 的返回类型(和参数类型)。

BTW you seem to have a misunderstanding, undefined references are not generally caused by missing header files, a missing header file would cause a compilation error.顺便说一句,您似乎有一个误解,未定义的引用通常不是由缺少 header 文件引起的,缺少 header 文件会导致编译错误。 Unresolved externals are generally caused by missing files (object files or library files) in the linking step.未解析的外部通常是由于链接步骤中缺少文件(目标文件或库文件)造成的。

UPDATE更新

Having looked at your code I can see that the problem is a typo.查看您的代码后,我可以看到问题是一个错字。 In chunkPipeline.hpp you declare a function createChunks but in chunkPipeline.cpp the same function is called createChunk .chunkPipeline.hpp你声明一个 function createChunks但在chunkPipeline.cpp相同的 function 被称为createChunk Disproving my earlier assertion that undefined references are caused missing files during linking, they can also be caused by typos.反驳我之前的断言,即未定义的引用是在链接期间导致丢失文件的,它们也可能是由拼写错误引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM