【问题标题】:Getting LNK1107 invalid or corrupt file: cannot read at 0x378 when trying to link .dll for OpenSceneGraph tutorial获取 LNK1107 无效或损坏的文件:尝试链接 OpenSceneGraph 教程的 .dll 时无法在 0x378 处读取
【发布时间】:2019-06-13 14:35:48
【问题描述】:

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

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

    #include <osg/ref_ptr>
    #include <osg/Referenced>
    #include <iostream>
    using namespace std;

    class MonitoringTarget : public osg::Referenced
    {
    public:
        MonitoringTarget(int id) : _id(id)
        {
            cout << "Constructing target " << _id << endl;
        }
    protected:
        int _id;
        virtual ~MonitoringTarget()
        {
            cout << "Destroy " << _id << endl;
        }
    };

    int main()
    {
        osg::ref_ptr<MonitoringTarget> target = new MonitoringTarget(0);
        cout << "Reference count before referring: "
            << target->referenceCount() << endl;
        osg::ref_ptr<MonitoringTarget> anotherTarget = target;
        cout << "Referenced count after referring: "
            << target->referenceCount() << endl;
    }

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

我在这里做错了什么?

【问题讨论】:

    标签: c++ visual-studio


    【解决方案1】:

    您需要链接到 .lib,而不是 .dll。 dll 路径必须在您的 PATH 中才能工作或与可执行文件位于同一文件夹中。

    【讨论】:

    • 感谢您的回复。我已经在 Configuration Properties->Debugging->Environment 中设置了路径,但仍然出现相同的错误
    • 错误是指程序构建但正在寻找.dll。我不知道需要设置的路径应该设置在哪里
    • 只需将dll与可执行文件放在同一文件夹中即可。如果它已经存在,那么你有一个 dll 依赖问题。
    • 在全局 PATH 环境变量中。那是它应该在的地方。或者在可执行文件旁边,这是安装程序所做的。
    • PATH 中的环境变量 Configuration Properties-&gt;Debugging-&gt;Environment 也应该可以工作。确保将其应用于所有配置。不知道为什么它让你失望了。我过去用过这个。
    猜你喜欢
    • 1970-01-01
    • 2013-04-28
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 2017-12-19
    • 2020-03-06
    • 2011-01-11
    • 2023-03-13
    相关资源
    最近更新 更多