SMILE link error with Visual Studio 2010

101 views Asked by At

I am working with an older version of a C++ SMILE library for Bayesian analysis that was freely available before they started selling it. I have no idea what compiler was used to create the libraries, but all I have are the headers and lib files. I am attempting to wrap these libraries with managed C++ code for use in our newer .Net applications build with Visual Studio 2010 SP1. Because I have to use the /MT switch, I have to create a DLL to export the class creation and functions to the CLR DLL project that wraps them into a new class.

The source for the first unmanaged DLL is like this, and has no issues compiling/linking into the DLL:

CPP_Network.h

#include "smile.h"

#pragma once

#ifndef DllExport
#define DllExport    __declspec( dllexport )
#endif

#if defined(__cplusplus)
extern "C"
{
#endif

DllExport DSL_network* DSL_network_Create();
DllExport void DSL_network_Release(DSL_network* instance);

#if defined(__cplusplus)
}
#endif

CPP_Network.cpp

#include "CPP_Network.h"

DSL_network* DSL_network_Create()
{
    return new DSL_network();
}

void DSL_network_Release(DSL_network* instance)
{
    if (instance != NULL)
        delete instance;
}

The managed wrapper source is like this, but generates linker errors below:

CLR_Network.h

#pragma once

#define SMILE_VC_NO_AUTOLINK
#define SMILEXML_VC_NO_AUTOLINK
#define SMILEARN_VC_NO_AUTOLINK

#include "CPP_Network.h"

using namespace System;

namespace smile {
    public ref class Network
    {
    private:
        DSL_network *instance;
    public:
        Network();
        ~Network();
    };
}

CLR_Network.cpp

#include "stdafx.h"

#include "CLR_Network.h"

smile::Network::Network()
{
    instance = DSL_network_Create();
}

smile::Network::~Network()
{
    DSL_network_Release(instance);
    instance = 0;
}

I get the following link errors when linking to the unmanaged DLL:

error LNK2028: unresolved token (0A0004C3) "public: __thiscall DSL_doubleArray::DSL_doubleArray(class DSL_doubleArray const &)" (??0DSL_doubleArray@@$$FQAE@ABV0@@Z) referenced in function "public: __thiscall DSL_Dmatrix::DSL_Dmatrix(class DSL_Dmatrix const &)" (??0DSL_Dmatrix@@$$FQAE@ABV0@@Z)
error LNK2028: unresolved token (0A0004C4) "public: void __thiscall DSL_doubleArray::CleanUp(void)" (?CleanUp@DSL_doubleArray@@$$FQAEXXZ) referenced in function "public: __thiscall DSL_doubleArray::~DSL_doubleArray(void)" (??1DSL_doubleArray@@$$FQAE@XZ)
error LNK2028: unresolved token (0A0004C6) "public: int __thiscall DSL_intArray::SetSize(int)" (?SetSize@DSL_intArray@@$$FQAEHH@Z) referenced in function "public: __thiscall DSL_intArray::DSL_intArray(class DSL_intArray const &)" (??0DSL_intArray@@$$FQAE@ABV0@@Z)
error LNK2019: unresolved external symbol "public: void __thiscall DSL_doubleArray::CleanUp(void)" (?CleanUp@DSL_doubleArray@@$$FQAEXXZ) referenced in function "public: __thiscall DSL_doubleArray::~DSL_doubleArray(void)" (??1DSL_doubleArray@@$$FQAE@XZ)
error LNK2019: unresolved external symbol "public: int __thiscall DSL_intArray::SetSize(int)" (?SetSize@DSL_intArray@@$$FQAEHH@Z) referenced in function "public: __thiscall DSL_intArray::DSL_intArray(class DSL_intArray const &)" (??0DSL_intArray@@$$FQAE@ABV0@@Z)
error LNK2019: unresolved external symbol "public: __thiscall DSL_doubleArray::DSL_doubleArray(class DSL_doubleArray const &)" (??0DSL_doubleArray@@$$FQAE@ABV0@@Z) referenced in function "public: __thiscall DSL_Dmatrix::DSL_Dmatrix(class DSL_Dmatrix const &)" (??0DSL_Dmatrix@@$$FQAE@ABV0@@Z)

I ran dumpbin on smile.lib and saw the following link:

??0DSL_doubleArray@@QAE@ABV0@@Z

Running undname on that and the one the linker is looking for shows the same function declarations:

C:\>undname ??0DSL_doubleArray@@QAE@ABV0@@Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "??0DSL_doubleArray@@QAE@ABV0@@Z"
is :- "public: __thiscall DSL_doubleArray::DSL_doubleArray(class DSL_doubleArray const &)"

C:\>undname ??0DSL_doubleArray@@$$FQAE@ABV0@@Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "??0DSL_doubleArray@@$$FQAE@ABV0@@Z"
is :- "public: __thiscall DSL_doubleArray::DSL_doubleArray(class DSL_doubleArray const &)"

I'm guessing that the newer compiler is looking for a newer version of the link. Is there a way to make this work correcting the references somehow?

0

There are 0 answers