1

I am trying to use the AWS Iot SDK in Embarcadero C++ Builder which I am using the Embedded C Version of the SDK. I was trying to use a generated DLL in the RAD Studio IDE but wasn't able to input the functions needed as it was all under namespaces and classes.

Hence why I have resolved to using the Embedded C version of the SDK as talked about in this question because of it's portability. Calling DLL Functions under a namespace in RAD Studio

With the Embedded C version of the SDK, I have again generated it to be a DLL file where I have used the code below to export the data structures and functions with this example below:

#ifdef PUBSNUB_EXPORTS
#define PUBSNUB_API __declspec(dllexport)
#else
#define PUBSNUB_API __declspec(dllimport)
#endif

PUBSNUB_API IoT_Error_t aws_iot_mqtt_publish(AWS_IoT_Client* pClient, const char* pTopicName, uint16_t topicNameLen,
    IoT_Publish_Message_Params* pParams); 

PUBSNUB_API IoT_Error_t aws_iot_mqtt_subscribe(AWS_IoT_Client *pClient, const char *pTopicName, uint16_t topicNameLen,
                                   QoS qos, pApplicationHandler_t pApplicationHandler, void *pApplicationHandlerData);

When I try to call these functions in RAD studio, I get the following errors, even with the generated lib file as instructed copied in the project folder. If I call these functions in a Visual Studio project, it will work completely fine.

[ilink32 Error] Error: Unresolved external '_iotClientConnectParamsDefault' referenced from C:\MICRO PLUS\RELEASE\MAINFORM.OBJ
[ilink32 Error] Error: Unresolved external '_iotClientInitParamsDefault' referenced from C:\MICRO PLUS\RELEASE\MAINFORM.OBJ
[ilink32 Error] Error: Unresolved external '_aws_iot_mqtt_publish' referenced from C:\MICRO PLUS\RELEASE\MAINFORM.OBJ
[ilink32 Error] Error: Unable to perform link
Sahil Bora
  • 173
  • 1
  • 12
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jan 14 '20 at 02:14
  • No because it's using functions from a DLL in a different IDE which is RAD studio. If I call the functions in Visual Studio it works fine. – Sahil Bora Jan 14 '20 at 02:32
  • The IDE is irrelevant. An unresolved external is an unresolved external. The reason for it is the same; in most cases, you've not included the proper libraries. I'm quite familiar with what RAD Studio is - I've been using it as long as it's existed. – Ken White Jan 14 '20 at 02:34
  • Well I've converted the DLL file from Visual Studio to a RAD Studio compatible version using the "implib" command. I've also included the lib file with #pragma comment(lib, AmazonAWSEmbeddedBuild) – Sahil Bora Jan 14 '20 at 02:51
  • Did you build the DLL yourself? – M.M Jan 14 '20 at 04:33
  • Yes I did build the dll myself – Sahil Bora Jan 14 '20 at 04:42

1 Answers1

2
  1. mangling

    for static linking you need to use correct combination of switches of implib because your DLL was not created by BCC it contains most likely different name mangling ... try :

    implib.exe -c -f -a winusb.lib winusb.dll
    

    or any of the 8 combinations of the switches (rename the winusb with your file).

  2. DLL must match the platform

    so if you got 32 bit executable your DLL must be also 32 bit ... otherwise you need a bridge DLL ... In case of windows drivers beware that 32 bit EXE/DLLs on 64bit OS will run in WOW64 which might be problematic accessing real HW insteead of emulated one.

    beware older implib versions do not handle 64bit DLLs (create empty 1024 byte libs)

  3. if nothing works use dynamic DLL linkign

    see Builder C++ calling VC++ class

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • The first solution has worked on my computer but when I copy the generated lib file and try to run it on my colleague's computer it's not working but I'll give the answer a tick :) – Sahil Bora Jan 14 '20 at 05:40
  • Do you have a solution for calling dll functions inside a RAD studio form inside Tmain::Tman() as I'm getting the same errors in a GUI project and not a console project. – Sahil Bora Jan 14 '20 at 05:53
  • @SahilBora you need to add the lib into the project either by IDE menu add to project or by using [#pragma comment(lib, "YourDLL.lib")](https://stackoverflow.com/a/57588644/2521214) in code at the right place (main form code). if it works on your computer and not in the school it might be because you did not have the same DLL or not targeting the same platfom (x86/x64) the lib and DLL is for. Also some DLL headers require additional configuration `#define` ... without more details I can only guess – Spektre Jan 14 '20 at 20:50
  • @SahilBora where exactly is your DLL located? is it where your exe is or on some path like program file or system32 ... the latter might pose a problem on x64 bit platform if done for 32 bit ... #bullet 3 should work no matter what ... but there are certain cases when even that does not work due to bug in winapi (present on w2k,wxp,w7... not sure about w8/w10 as I do not use those) there are DLLs that can not be fully loaded and usually up to 5% of functions are not linkable ... I encountered this with some old C mangled DLLs for 3dfx emulator. But such DLLs are really rare to find – Spektre Jan 14 '20 at 21:01
  • In RAD Studio I am calling the generated dll by using #pragma comment(lib, "MyDll.lib") in the mainForm.cpp file. In regards to the platform, on my colleague's computer i'ts using the same x86 platform for a Windows GUI program we are trying to use the dll for. I've copied the generated lib file in the project directory. – Sahil Bora Jan 14 '20 at 22:09
  • 1
    It's turns out for Windows GUI projects in RAD studio, all you had to do was go to "Project->Add to Project->Select your lib file" and it solved the problem – Sahil Bora Jan 14 '20 at 23:36