sgtHale
sgtHale

Reputation: 1567

Visual Studio 2017 cannot build with a library

So I'm using a library called Milestone SDK and I have followed instructions to link this basic library into my program. Understanding the library itself doesn't matter since I'm just trying to get a library working.

I've added include directory to "C:\Program Files\Milestone\MIPSDK\Include"

I've added linker to "C:\Program Files\Milestone\MIPSDK\Lib\x64",

I've added "ToolkitFactoryProvider.lib" to additional dependancies, and I've made sure that the build is targeting x64 Debug and included the ToolkitFactoryProvider.dll into the exe directory. And wrote this basic program:

#include <set>
#include <iostream>
#include <Toolkits/ToolkitInterface.h>
#include <Toolkits/ToolkitFactoryProvider.h>
#include "stdafx.h"

using namespace std;
using namespace NmToolkit;

int main(){
    ImToolkitFactory* p_fac;
    CmToolkitFactoryProvider provider;
    p_fac = provider.CreateInstance();

    if (p_fac == NULL) {
        return -1;
    }
    provider.DeleteInstance(p_fac);
    return 0;
}

However, when I build, VS2017 throws up: "NmToolkit namespace does not exist" "ImToolkitFactory undeclared identifier" "etc."

The editor itself recognizes the names and class names so I don't understand what I did wrong if I followed loads of tutorials to add a library. Any help? Could it be something wrong with the library itself? I even tried to add it in the VC++ Directories menu and C/C++ menu.

Upvotes: 0

Views: 609

Answers (1)

Sami Sallinen
Sami Sallinen

Reputation: 3494

The problem is likely the include statement for stdafx.h. It should be the 1st include statement in the .cpp file.

If your project uses precompiled headers, this include statement has a special meaning: the contents of the .h file are compiled and the compiler state is then dumped to a .pch file. Then the state is loaded whenever the compiler sees this include statement.

This speeds up compilation of large projects when you put all often used include files in stdafx.h. The side effect is that the compiler forgets anything that was seen before the precompiled header include statement.

Upvotes: 2

Related Questions