0

I am trying to get a third party reconstruction library ReconstructMe working by creating a c++ dll and call it within unity(c#).

I have get it working using supplied dll but calling unmanaged function calls are hitting performance on every update for multiple functions e.g:

on every update I am calling below necessary calls:

reme_sensor_grab
reme_sensor_prepare_images
reme_sensor_track_position
reme_sensor_update_volume
reme_surface_generate 

For optimization, the idea is if I can make a new DLL including all above functions, calls and this DLL import function will call once per update from unity(c#) or may be call it just once and get data from callbacks.

I have simply used below code to check if I am able to get it working, unfortunately I am getting LNK2019:

RemeDLL.obj : error LNK2019: unresolved external symbol __imp_reme_context_create referenced in function “private: void __cdecl RemeDLL::StartScan(void)” (?StartScan@RemeDLL@@AEAAXXZ)
1>c:\Projects\RemeDLL\x64\Debug\RemeDLL.dll : fatal error LNK1120: 1 unresolved externals

#include <iostream>
#include <reconstructmesdk/reme.h>
using namespace std;

class RemeDLL
{
    __declspec(dllexport) void StartScan()
    {
        // Create a new context
        reme_context_t context;
        reme_context_create(&context);
        //...
    }
};

Here are definitions from SDK:

typedef struct _reme_context* reme_context_t;

LIBRECONSTRUCTMESDK_LIBRARY_INTERFACE
reme_error_t reme_context_create(reme_context_t *c);

#define LIBRECONSTRUCTMESDK_LIBRARY_INTERFACE __declspec(dllimport)

Can someone please suggest or give pointers how can I go around this ? Do I need some kind of layers for linking dll to import first and then call dll to export function, please advice. Thanks.

Syed
  • 550
  • 1
  • 7
  • 22
  • how do you build it or what's your IDE? (Visual Studio?) – hauron Jul 08 '15 at 07:37
  • Yes its visual studio. I build it for x64 sdk library and my environment is also set up for x64. – Syed Jul 08 '15 at 07:41
  • 1
    it's a small world but I unfortunately answered a similar question: http://stackoverflow.com/questions/20058864/how-to-include-libraries-in-visual-studio-2012/20059167#20059167 (basically 5 steps to use a dll). you may need to provide the dll build directory somewhere as well – hauron Jul 08 '15 at 07:45
  • Thanks, but I doubt I have already added library successfully. Removing __declspec(dllexport) from above code in StartScan creates me dll but I am afraid I wont be able to import it. – Syed Jul 08 '15 at 07:55
  • Thanks @hauron, I followed step and it worked! I was previously relying on SDK installer setting for lib and linker settings. Thanks again :) – Syed Jul 08 '15 at 08:37

1 Answers1

-1
  1. Add paths to ReconstructMe inc and lib folders to your project properties;
  2. Add line #pragma comment(lib, "LibReconstructMeSDK.lib") to your source code.
Ari0nhh
  • 5,720
  • 3
  • 28
  • 33
  • 2
    awful way to specify dependencies - unmanagable, not cross-platform, also it doesn't really belong in a translation unit, but should be fed to the linker instead. the translation unit only needs the appropriate header files (inside the 'inc') – hauron Jul 08 '15 at 07:38
  • @hauron: I'd disagree with your opinions. Specifying the dependency where it happens (i.e. in the code) is likely the most natural and manageable way to document and resolve dependencies. A client can now simply include a header, and be done. No fiddling with linker settings. I fail to see any merit in specifying platform-specific dependencies in a platform-independent way. Being cross-platform has no intrinsic value. – IInspectable Jul 09 '15 at 12:20
  • @IInspectable: I agree specifying the dependency where it happens is good, but I'd disagree with your disagreeing :) in this case. For me this is a binary dependency - important for linker or whatever other build tool the client uses. I'd hate to scan the header file for exact lib names, and I can only imagine the hell with relative paths. Linker settings are... just for that - linking binary files. – hauron Jul 10 '15 at 11:16