0

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?

Monkone
  • 43
  • 7

1 Answers1

2

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.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • 1
    Thanks for the response. I've set the path in Configuration Properties->Debugging->Environment but still getting the same error – Monkone Jan 19 '19 at 16:37
  • By error I mean that the program builds but is looking for the .dll. I don't know where the path that needs to be set is meant to be set – Monkone Jan 19 '19 at 16:46
  • Just put the dll in the same folder as the executable. If it is already there then you have a dll dependency problem. – drescherjm Jan 19 '19 at 16:47
  • Hi drescherjm. That got the .exe running, so no dll dependency issue :) Where would I need to specify in VS the path to the dlls in order to not have to copy the dlls to the .exe every time? – Monkone Jan 19 '19 at 16:53
  • 1
    In the global PATH environment variable. That's where it should be. Or next to the executable, which is what installers do. – Matthieu Brucher Jan 19 '19 at 16:57
  • 2
    The `PATH` environment variable in `Configuration Properties->Debugging->Environment` should also work. Make sure you apply it to all configurations. Not sure why it failed you. I have used this in the past. – drescherjm Jan 19 '19 at 16:59
  • huh... I've already tried that before and got no joy. Specifically I put the "C:\Users\Monkone\source\OpenSceneGraph-3.6.3-VC2017-64-Debug\bin" in the top text box for environment. It's the correct path but I have to be doing something wrong here as it's not seeing the path for some reason – Monkone Jan 19 '19 at 17:03
  • That is not how you set the PATH environment variable. – drescherjm Jan 19 '19 at 17:06
  • k, I'll try to find a clearer tutorial for that than the last one I looked at. Thanks for helping clear things up – Monkone Jan 19 '19 at 17:10
  • It should start with `PATH=` in that box. You also probably want to keep the previous path also. Here is an example: https://stackoverflow.com/a/2916103/487892 – drescherjm Jan 19 '19 at 17:11
  • Brilliant. Thank you kindly! – Monkone Jan 19 '19 at 17:13