获取无效或损坏的文件LNK1107:尝试链接 OpenSceneGraph 教程.dll时无法0x378读取

Getting LNK1107 invalid or corrupt file: cannot read at 0x378 when trying to link .dll for OpenSceneGraph tutorial

本文关键字:dll 教程 OpenSceneGraph 读取 0x378 链接 损坏 无效 文件 LNK1107 获取      更新时间:2023-10-16

我正在尝试在Visual Studio上设置OpenSceneGraph,以便我可以运行一些教程,我相信我的问题是我不知道如何在Visual Studios上正确设置环境并让程序正确查看库文件。

有问题的代码仅用于osg智能指针演示

    #include <osg/ref_ptr>
    #include <osg/Referenced>
    #include <iostream>
    using namespace std;
    
    class AClass : public osg::Referenced
    {
    public:
        AClass(int id) : _id(id)
        {
            cout << "Constructing object " << _id << endl;
        }
    protected:
        int _id;
        virtual ~AClass()
        {
            cout << "Destroy " << _id << endl;
        }
    };
    
    int main()
    {
        osg::ref_ptr<AClass> obj = new AClass(0);
        cout << "Reference count before referring: "
            << obj->referenceCount() << endl;
        osg::ref_ptr<AClass> anotherObject = object;
        cout << "Referenced count after referring: "
            << object->referenceCount() << endl;
    }

如果我在属性>Linker->其他依赖项中指向osgd.lib,这将构建,但是当我尝试运行它时,会发生系统错误,它指出程序无法启动,因为"osgd.ll从您的计算机中丢失",但是如果我指向osgd.dll它将无法构建并引发以下错误: "LNK1107无效或损坏的文件:无法在 OSG1 C:\Users\Monkone\source\OpenSceneGraph-3.6.3-VC2017-64-Debug\bin\osgd.dll 读取0x378"

我在这里做错了什么?

您需要针对 .lib 而不是.dll进行链接。dll 路径必须位于 PATH 中才能正常工作,或者与可执行文件位于同一文件夹中。