Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error on Windows 11 - Visual Studio community 2022 - Cmake 3.29.6 #500

Open
FrankRobot opened this issue Jun 22, 2024 · 10 comments
Open
Assignees
Labels
bug Confirmed bug fix added A fix has been pushed to the repo and is being tested upstream Problem with upstream library
Milestone

Comments

@FrankRobot
Copy link

Hi, I've followed the instructions for building paho.mqtt.c and then paco.mqtt.cpp.
I can build paho.mqtt.c, but when I try to build paco.mqtt.cpp I always get this error:

cmake -Bbuild -H. -DCMAKE_INSTALL_PREFIX=C:\mqtt\paho-cpp -DPAHO_BUILD_SAMPLES=ON -DPAHO_WITH_SSL=OFF -DCMAKE_PREFIX_PATH=C:\mqtt\paho-c
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- Configuring done (0.2s)
CMake Error at src/CMakeLists.txt:82 (target_link_libraries):
Target "paho-mqttpp3-static" links to:

eclipse-paho-mqtt-c::paho-mqtt3a-static

but the target was not found. Possible reasons include:

* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.

-- Generating done (1.7s)
CMake Generate step failed. Build files cannot be regenerated correctly.

@FrankRobot FrankRobot changed the title Building error on Windows 11 - Visual Studio community 2022 - Cmake 3.29.6 Build error on Windows 11 - Visual Studio community 2022 - Cmake 3.29.6 Jun 22, 2024
@fpagliughi
Copy link
Contributor

Is this with the new v1.4.0?

@FrankRobot
Copy link
Author

Hi fpaglughi, Yes, with the v1.4.0. I've tried also the dev branch.

@fpagliughi
Copy link
Contributor

OK, It's looking like the problem is with the build instructions in the README, combined with the new version being more strict about what it links against. Now the shared C++ library only links against the shared C library, and static against static. I may loosen this up a bit, but want to avoid some linker problems when mixing these.

Anyway, the problem is probably that the C library is being built just with the shared DLL, but not that static library, and the C++ library is being built the other way (static but not shared).

The easiest way to avoid this problem is to build both libraries together using the -DPAHO_WITH_MQTT_C=ON CMake flag when building the C++ library. This ensures that both libraries are configured in the same manner, and compatible.

The instructions are near the top of the README and generally apply to all platforms. This is the new recommended way to build the C & C++ libraries when you will primarily just be using the C++ API.

$ git clone https://github.com/eclipse/paho.mqtt.cpp
$ cd paho.mqtt.cpp
$ git co v1.4.0

$ git submodule init
$ git submodule update

$ cmake -Bbuild -H. -DPAHO_WITH_MQTT_C=ON -DPAHO_BUILD_EXAMPLES=ON
$ sudo cmake --build build/ --target install

But you can still both of them separately. On Windows you will just need to be sure to configure and build the static libraries (or turn on shared and turn off static for both libraries).

To build the static libraries for Paho C, just re-run CMake with -DPAHO_BUILD_STATIC=ON, then recompile and install.

After that, just recompile the C++ library and it should build fine.

In the meantime, assuming that works, lets keep this issue open to remind me to fix the README.

@fpagliughi
Copy link
Contributor

Oh, no, wait...

I was sure I tested all the combinations, but I was more concerned with getting PAHO_WITH_MQTT_C working, that I let this slip.

It appears that if you enable both targets (shared and static) in the Paho C library, it is building the static libraries but not exporting the -static CMake target!

As a quick fix, rebuild the Paho C library with static turned on and shared turned off, -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_SHARED=OFF

Sorry about the confusion. I will try to figure out the problem in the C library build and send a PR upstream.

@fpagliughi
Copy link
Contributor

OK. I sent a PR to the upstream Paho C lib.

@fpagliughi fpagliughi modified the milestones: v1.4.1, v1.5 Jun 23, 2024
@FrankRobot
Copy link
Author

FrankRobot commented Jun 27, 2024

Thanks Frank! The workaround works, build ok!

@fpagliughi fpagliughi added the fix added A fix has been pushed to the repo and is being tested label Jun 27, 2024
@1096233486
Copy link

Oh, no, wait...

I was sure I tested all the combinations, but I was more concerned with getting PAHO_WITH_MQTT_C working, that I let this slip.

It appears that if you enable both targets (shared and static) in the Paho C library, it is building the static libraries but not exporting the -static CMake target!

As a quick fix, rebuild the Paho C library with static turned on and shared turned off, -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_SHARED=OFF

Sorry about the confusion. I will try to figure out the problem in the C library build and send a PR upstream.

bulid success,thinks from swpu😆

@acidtonic
Copy link

I am trying to get this working on Alpine and having similar issues but once I try the paho_c bundled, shared=off static=on config, I get errors about missing CMakeLists.txt

This was a mature building project before, kinda bummed about this.

cmake -Bbuild -H. -DCMAKE_CXX_COMPILER=clang++ -DPAHO_WITH_MQTT_C=ON -DPAHO_BUILD_SHARED=OFF -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_DOCUMENTATION=OFF -DPAHO_BUILD_SAMPLES=FALSE

The source directory
/BUILD/paho.mqtt.cpp/externals/paho-mqtt-c
does not contain a CMakeLists.txt file.

@dinesht27
Copy link

Hello All,
I am working on C++ project of compiling and sending messages via MQTT client.
Visual Studio Version - 17 2022
Compiler - v142

I have used following steps to build and install the Paho C and C++, and wanted to link the libraries to the C++ Project.
Build Steps which was successful. - (Build with Static and no shared libs as previous comments.)
C
-> cd paho.mqtt.c
-> cmake -G "Visual Studio 17 2022" -Ax64 -Bbuild -H. -DCMAKE_INSTALL_PREFIX=C:\mqtt\paho-c -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_SHARED=OFF
-> cmake --build build/ --target install --config Release

C++ (For this I have used the following release - paho.mqtt.cpp-1.4.1 (the only version worked for me) )
->cd paho.mqtt.cpp
->cmake -G "Visual Studio 17 2022" -Ax64 -Bbuild -H. -DCMAKE_INSTALL_PREFIX=C:\mqtt\paho-cpp -DPAHO_BUILD_SAMPLES=ON -DPAHO_WITH_SSL=OFF -DCMAKE_PREFIX_PATH=C:\mqtt\paho-c
->cmake --build build/ --target install --config Release

The following is my CmakeList.txt where I also using the async for the target linking of libs
CMakeLists.txt

And I also added my test example for tesing this MQTT publisher, -
EbMQTTPublisher.cpp.txt

EbMQTTPublisher.h.txt

I have the following build error which I am not able to resolve for the past days -

paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _Cnd_timedwait_for referenced in function "public: bool __cdecl std::condition_variable::wait_for<__int64,struct std::ratio<1,1000>,class <lambda_8753e8241f2a5a762f79a862fae56c72> >(class std::unique_lock &,class std::chrono::duration<__int64,struct std::ratio<1,1000> > const &,class <lambda_8753e8241f2a5a762f79a862fae56c72>)" (??$wait_for@_JU?$ratio@$00$0DOI@@std@@v<lambda_8753e8241f2a5a762f79a862fae56c72>@@@condition_variable@std@@QEAA_NAEAV?$unique_lock@Vmutex@std@@@1@AEBV?$duration@_JU?$ratio@$00$0DOI@@std@@@chrono@1@V<lambda_8753e8241f2a5a762f79a862fae56c72>@@@z)
1>paho-mqttpp3-static.lib(token.obj) : error LNK2001: unresolved external symbol _Cnd_timedwait_for

I would appreciate some suggestion and support here on where I have made things wrong, also I couldnt find much possibilities for installing the dlls, also if you ans this in the side.

Thank you much.
BR
Dinesh

@1096233486
Copy link

Hello All, I am working on C++ project of compiling and sending messages via MQTT client. Visual Studio Version - 17 2022 Compiler - v142

I have used following steps to build and install the Paho C and C++, and wanted to link the libraries to the C++ Project. Build Steps which was successful. - (Build with Static and no shared libs as previous comments.) C -> cd paho.mqtt.c -> cmake -G "Visual Studio 17 2022" -Ax64 -Bbuild -H. -DCMAKE_INSTALL_PREFIX=C:\mqtt\paho-c -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_SHARED=OFF -> cmake --build build/ --target install --config Release

C++ (For this I have used the following release - paho.mqtt.cpp-1.4.1 (the only version worked for me) ) ->cd paho.mqtt.cpp ->cmake -G "Visual Studio 17 2022" -Ax64 -Bbuild -H. -DCMAKE_INSTALL_PREFIX=C:\mqtt\paho-cpp -DPAHO_BUILD_SAMPLES=ON -DPAHO_WITH_SSL=OFF -DCMAKE_PREFIX_PATH=C:\mqtt\paho-c ->cmake --build build/ --target install --config Release

The following is my CmakeList.txt where I also using the async for the target linking of libs CMakeLists.txt

And I also added my test example for tesing this MQTT publisher, - EbMQTTPublisher.cpp.txt

EbMQTTPublisher.h.txt

I have the following build error which I am not able to resolve for the past days -

paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _Cnd_timedwait_for referenced in function "public: bool __cdecl std::condition_variable::wait_for<__int64,struct std::ratio<1,1000>,class <lambda_8753e8241f2a5a762f79a862fae56c72> >(class std::unique_lock &,class std::chrono::duration<__int64,struct std::ratio<1,1000> > const &,class <lambda_8753e8241f2a5a762f79a862fae56c72>)" (??$wait_for@_JU?$ratio@$00$0DOI@@std@@v<lambda_8753e8241f2a5a762f79a862fae56c72>@@@condition_variable@std@@QEAA_NAEAV?$unique_lock@Vmutex@std@@@1@AEBV?$duration@_JU?$ratio@$00$0DOI@@std@@@chrono@1@V<lambda_8753e8241f2a5a762f79a862fae56c72>@@@z) 1>paho-mqttpp3-static.lib(token.obj) : error LNK2001: unresolved external symbol _Cnd_timedwait_for

I would appreciate some suggestion and support here on where I have made things wrong, also I couldnt find much possibilities for installing the dlls, also if you ans this in the side.

Thank you much. BR Dinesh

Previously, I successfully built using gcc/g++on a Linux system, but did not use VS. I hope these points can help you:
1、 Ensure to build C first and then build CPP
2、At that time, there seemed to be some issues with the static construction of this project,You can try building SHARED library,-DPAHO_BUILD_STATIC=OFF -DPAHO_BUILD_SHARED=ON(you will get .dll file on windows)
3、If you are building a QT project, you can try using QT's Mqtt library(At that time, I was coding QT project)
4、Seeking help from the versatile GPT👍😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug fix added A fix has been pushed to the repo and is being tested upstream Problem with upstream library
Projects
None yet
Development

No branches or pull requests

5 participants