c++visual-studio

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


I'm trying to get OpenSceneGraph set up on visual studio so I can run through some tutorials and I believe my issue is that I do not know how to correctly set up the environment on visual studios and get the program to look at the library files correctly.

The code in question is just for a osg smart pointer demonstration

    #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;
    }

If I point to osgd.lib in Properties->Linker->additional dependencies this will build but when I try to run it a system error occurs whereby it states the program cannot start because "osgd.ll is missing from your computer", however if I point to osgd.dll it will fail to build and throw up the following error: "LNK1107 invalid or corrupt file: cannot read at 0x378 OSG1 C:\Users\Monkone\source\OpenSceneGraph-3.6.3-VC2017-64-Debug\bin\osgd.dll"

What am I doing wrong here?

Example here: https://github.com/mcleantom/so-79276056


Solution

  • You need to link against the .lib, not the .dll. The dll path must be in your PATH to work or in the same folder as the executable.