eclipse-paho / paho.mqtt.c

An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/
https://eclipse.org/paho
Other
1.97k stars 1.1k forks source link

Compile Issue with OS Defines in VS Code #1481

Open nicofer00 opened 6 months ago

nicofer00 commented 6 months ago

https://github.com/eclipse/paho.mqtt.c/blob/6b1e202a701ffcdaa277b5644ed291287a70a7aa/test/thread.c#L28

At first, trying to build on Windows 10 machine with OpenSSL variables passed in. Testing is enabled by default but would cause the build to fail at compile time. Probably should also check for _WIN32 because I don't think _WINDOWS was being defined. When I added it in manually to the CMakeLists.txt then it could successfully compile. I also tried alternatively adding checks to the test files to guard windows compilation better.

image

I made changes to make the statements #if !defined(_WINDOWS) && !defined(_WIN32) && !defined(_WIN64) and #if defined(_WINDOWS) || defined(_WIN32) || defined(_WIN64) which successfully compiled and ran the tests for me.

Current work around is to skip it in my compilation with the command: cmake -G "Unix Makefiles" -B build -DCMAKE_INSTALL_PREFIX=/ -DPAHO_BUILD_STATIC=TRUE -DPAHO_ENABLE_TESTING=FALSE -DPAHO_WITH_SSL=TRUE -DOPENSSL_ROOT_DIR="C:\Program Files\OpenSSL-Win64\"

then: cmake --build build/ --target install

which worked as well.

nicofer00 commented 6 months ago

paho_issue_1481.txt

here is a diff of changes that allowed me to successfully compile with tests enabled in windows. Probably not the best way to go about it but just to show it works...

jumoog commented 6 months ago

I have the following Preprocessor Definitions

%(PreprocessorDefinitions);WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;WIN32_LEAN_AND_MEAN;CMAKE_INTDIR="Debug"

jumoog commented 6 months ago

You have to set it manually:

https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference

nicofer00 commented 6 months ago

Ok so VS Code configuration thing, I guess! The extra compile guards could take away the need for that manual step if that's desirable in the future, but this makes sense to me.

icraggs commented 2 months ago

A bit late, but the Windows builds are run on AppVeyor:

https://ci.appveyor.com/project/eclipsewebmaster/paho-mqtt-c/builds/50529165/job/q7laclonnv1ejq2g?fullLog=true