0

I'm trying to build paho_mqtt.c on Windows X86 (64-bit). I'm using Visual Studio Community 2013. Its a supported configuration.

To build paho_mqtt.c for 64-bit, one needs OpenSSL compiled for Windows 64-bit. To build OpenSSL I found I needed a new version of Active Perl. I then used the following commands to build OpenSSL:

  • perl Configure -no-asm VC-WIN64A
  • nmake
  • nmake test

All the tests worked so I have believe I have working SSL/TLS libraries.

When building MQTT paho it couldn't find the ssl.h. I used the trick on this page listed below to set the environment variables so msbuild would get the include path from the environment variables:

Adding additional library and include paths when compiling from command line

That worked and paho found ssl.h.

Next msbuild of paho.mqtt.c could not find libeay32 / ssleay32.dll. First I used the trick from above again so msbuild would search the correct directory for the openssl libraries. Although the new libraries work, the library names are different. I used the information in 2) on Compiling OpenSSL for Windows, Linux, and Macintosh and I did the following:

cp libssl.lib libeay32.lib
cp libcrypto.lib ssleay32.lib

This is questionable I know, but it appears to have worked; that is, the link command that was failing now runs without warning or error. But it might have just deferred any unresolved symbol problems until later.

msbuild is failing later when trying to link an executable (shown at the bottom of this post). msbuild is complaining it cannot resolve the MQTTClient_* funcitons/symbols (e.g. MQTTClient_connect). Those functions are all in MQTTClient.c, and msbuild built MQTTClient.obj without emitting any errors.

My questions revolve around "what is the real problem?":

  • Is the problem with MQTTClient.obj:
    • maybe it is not included in the link command?
    • or maybe the symbols are not in the object file?
  • Is the problem that I renamed the libraries?

msbuild is not reporting that it cannot find the MQTTClient.obj. If the problem is with the openssl libraries I expect it would report some openssl symbols are not found.

On linux I would use nm -g to see whether the undefined symbols are in the MQTT_Client.obj. How do I verify this in Windows?

Thanks for any help you can provide,


Link:
  C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.exe" /INCREMENTAL:NO /NOLOGO /LIBPA
  TH:"C:\Users\don\paho.mqtt.c\Windows Build\\x64\Release" "paho-mqtt3a.lib" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc3
  2.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.pdb" /SUBSYSTEM:CONSOLE /O
  PT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.lib" /MACHINE:X64 x64\Release\paho_cs_pub.obj
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_create [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_yield [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_setCallbacks [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_disconnect [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_publish [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_destroy [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
paho_cs_pub.obj : error LNK2001: unresolved external symbol MQTTClient_connect [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
C:\Users\don\paho.mqtt.c\Windows Build\x64\Release\paho-cs-pub.exe : fatal error LNK1120: 7 unresolved externals [C:\Users\don\paho.mqtt.c\Windows Build\stdoutsuba\stdoutsuba.vcxproj]
jww
  • 97,681
  • 90
  • 411
  • 885
Don Mclachlan
  • 419
  • 4
  • 8
  • Your link command is missing the OpenSSL import libraries for `libeay32.lib` and `ssleay32.lib`. `MQTTClient_create` is *not* from OpenSSL, and you need that library, too. You should find the library `MQTTClient_create` and friends are part of, and add either (1) the library name if its static linking; or (2) `/implib:XXX` if its dynamically linking. Also see [/IMPLIB (Name Import Library)](https://msdn.microsoft.com/en-us/library/67wc07b9.aspx) on MSDN. If its a – jww Jul 20 '17 at 18:17
  • Instead of using msbuild I've opened the solution in Visual Studio Community 2013 and added C:\msys64\usr\local\ssl\lib to properties/Library Directory (and ...\bin for the dll). Visual Studio is still reporting, "error LINK1181: cannot open input file "libeay32.lib".) Why? Can it not find it? Is there a problem with the file? $ ls -l C:/msys64/usr/local/ssl/lib/libeay32.lib -rw-r--r-- 1 CRC None 802648 Jul 20 15:51 C:/msys64/usr/local/ssl/lib/libeay32.lib $ file !$ C:/msys64/usr/local/ssl/lib/libeay32.lib: current ar archive – Don Mclachlan Jul 21 '17 at 17:32
  • Grr. It seems I added that path in the wrong place in the properties. Adding it to Linker->General->Additional Library Directories seems to be getting me somewhere. – Don Mclachlan Jul 21 '17 at 17:46
  • The mqtt test files are trying to #include C/C++->.General->"Additional Include Directories" path? – Don Mclachlan Jul 21 '17 at 18:28
  • That was it. So if someone writes code including a .c file, to build it with Visual Studio, one needs to add the path to the .c file to Properites->VC++ Directories->Include Directories. – Don Mclachlan Jul 21 '17 at 18:39
  • *"... one needs to add the path to the .c file to Properites->VC++ Directories->Include Directories..."* sounds wrong. You add source files to the `ItemGroup` with the `ClCompile` nodes. Look at a typical `vcxproj` file; its just a XML file. Both Visual Studio and MSbuild uses the `vcxproj` file. Here's a sample one but its not a good example because its so big: [`cryptlib.vcxproj`](https://github.com/weidai11/cryptopp/blob/master/cryptlib.vcxproj). Also see [How to: Add Existing Items to a Project](https://msdn.microsoft.com/en-us/library/9f4t9t92(v=vs.100).aspx) on MSDN. – jww Jul 21 '17 at 18:54

0 Answers0