oymotion / gForceSDKCXX

This repository include gForce SDK dll files and some simple examples
Apache License 2.0
8 stars 1 forks source link

linker error, unresolved symbol #3

Closed Andrey1994 closed 4 years ago

Andrey1994 commented 4 years ago

Hello,

I am using Cmake instead VS solution to build my dll on top of gforce lib and getting linker error:

"E:\folder\brainflow\third_party\gForceSDKCXX\build64\ALL_BUILD.vcxproj" (default target) (1) ->
       "E:\folder\brainflow\third_party\gForceSDKCXX\build64\gForceSDKWrapper.vcxproj" (default target) (3) ->
       (Link target) ->
         wrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::shared_ptr<class gf::Hub> __cdecl gf::HubManager::getHubInstance(class std::basic_str
       ing<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?getHubInstance@HubManager@gf@@SA?AV?$shared_ptr@VHub@gf@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V
       ?$allocator@D@2@@4@@Z) referenced in function "void __cdecl `dynamic initializer for 'pHub''(void)" (??__EpHub@@YAXXZ) [E:\folder\brainflow\third_party\gForceSDKCXX\build64\gForceSDKWrapper.vc
       xproj]
         E:\folder\brainflow\third_party\gForceSDKCXX\build64\Release\gForceSDKWrapper.dll : fatal error LNK1120: 1 unresolved externals [E:\folder\brainflow\third_party\gForceSDKCXX\build64\gForceSD
       KWrapper.vcxproj]

    0 Warning(s)
    2 Error(s)

But I linked gforce lib, linker cmd:

         D:\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:"E:\folder\brainflow\third_party\gForceSDKCXX\build64\Release\gForceSDKWr
         apper.dll" /INCREMENTAL:NO /NOLOGO ..\lib\gforce64.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFES
         TUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"E:/folder/brainflow/third_party/gForceSDKCXX/build64/Release/gForceSDKWrapper.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /N
         XCOMPAT /IMPLIB:"E:/folder/brainflow/third_party/gForceSDKCXX/build64/Release/gForceSDKWrapper.lib" /MACHINE:X64  /machine:x64 /DLL gForceSDKWrapper.dir\Release\wrapper.obj

As you can see there is ..\lib\gforce64.lib Am I missing smth? It looks like unimplemented method in lib.

I use VS 2017, target windows sdk 8.1

Andrey1994 commented 4 years ago

WIP Code: https://github.com/brainflow-dev/brainflow/tree/oymotion/third_party/gForceSDKCXX if you want to reproduce it locally. I've taken lib and dll files from master branch of this repo.

I wanna add a wrapper dll on top of gforce lib which will push data to a queue and use this wrapper to integrate this device to BrainFlow(https://github.com/brainflow-dev/brainflow)

Andrey1994 commented 4 years ago

Checked exported functions, there is such method:

image

But it looks like c++ name mangling issue... If you look at linking error and at found symbol you will notice that they do not match

Andrey1994 commented 4 years ago

In error which I have basic_string@DU?$char_traits@D in exported symbols basic_string@_WU?$char_traits@_W@std@@V?.

I think there is one reliable way to fix it - drop HubManager class and add plain C method(wo classes) to return an instance of Hub object, and add

#ifdef __cplusplus
extern "C"
{
#endif

with declspec(dllexport) in front of method and cdecl calling convention

Can you do it?

Andrey1994 commented 4 years ago

I've found a clue for this issue - in your vs solution you use character set Unicode while by default in Cmake its different. It leads to different name mangling. Compiles fine with charset unicode.

But I still think that it would be much better if you provide a plain C method to create Hub object and it will prevent issues like this.

BigBro2014 commented 4 years ago

Thank you, Andrey1994. gForceSDKCXX is intended for C++ based programs. But it's resonable that we offer a wrapped C lib.