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

unresolved external symbol "private: static struct MQTTAsync_createOptions const mqtt::create_options::DFLT_C_STRUCT" #304

Closed
MikeMakes opened this issue Nov 10, 2020 · 14 comments
Assignees
Labels
fix added A fix has been pushed to the repo and is being tested
Milestone

Comments

@MikeMakes
Copy link

MikeMakes commented Nov 10, 2020

Compiling latest paho cpp with the latest paho c (installed without errors), with visual code 2019 for windows 10 results in:

LNK2019 unresolved external symbol "private: static struct MQTTAsync_createOptions const mqtt::create_options::DFLT_C_STRUCT" (?DFLT_C_STRUCT@create_options@mqtt@@0UMQTTAsync_createOptions@@b) referenced in function main async_publish_time C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\async_publish_time.obj

at the compilation of Project: rpc_math_srvr, Configuration: Release x64

All was build as Readme says, it does not work either compiling from VS gui or powershell.

  • OS: [Windows 10 x64
  • Visual Code 2019
  • Latest master paho mqtt c & cpp

Thanks you for this library, amazing work, I used it a lot recently ^^

VS compile output [edited, more readable]

1>------ Build started: Project: ZERO_CHECK, Configuration: Release x64 ------
1>Checking Build System
2>------ Build started: Project: paho-cpp-objs, Configuration: Release x64 ------
2>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/CMakeLists.txt
2>async_client.cpp
2>client.cpp
2>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(71,8): warning C4834: discarding return value of function with 'nodiscard' attribute
2>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(74,8): warning C4834: discarding return value of function with 'nodiscard' attribute
2>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(81,8): warning C4834: discarding return value of function with 'nodiscard' attribute
2>connect_options.cpp
2>create_options.cpp
2>disconnect_options.cpp
2>iclient_persistence.cpp
2>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\iclient_persistence.cpp(113,14): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
2>message.cpp
2>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\message.cpp(115,38): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
2>properties.cpp
2>response_options.cpp
2>ssl_options.cpp
2>string_collection.cpp
2>subscribe_options.cpp
2>token.cpp
2>topic.cpp
2>will_options.cpp
2>Generating Code...
2>paho-cpp-objs.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\paho-cpp-objs.dir\Release\paho-cpp-objs.lib
2>Done building project "paho-cpp-objs.vcxproj".
3>------ Build started: Project: paho-mqttpp3, Configuration: Release x64 ------
4>------ Build started: Project: paho-mqttpp3-static, Configuration: Release x64 ------
3>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/CMakeLists.txt
3>Auto build dll exports
3> Creating library C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/build/src/Release/paho-mqttpp3.lib and object C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/build/src/Release/paho-mqttpp3.exp
4>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/CMakeLists.txt
3>paho-mqttpp3.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\Release\paho-mqttpp3.dll
5>------ Build started: Project: async_consume, Configuration: Release x64 ------
6>------ Build started: Project: async_publish, Configuration: Release x64 ------
7>------ Build started: Project: async_publish_time, Configuration: Release x64 ------
8>------ Build started: Project: async_subscribe, Configuration: Release x64 ------
9>------ Build started: Project: data_publish, Configuration: Release x64 ------
10>------ Build started: Project: mqttpp_chat, Configuration: Release x64 ------
11>------ Build started: Project: pub_speed_test, Configuration: Release x64 ------
4>paho-mqttpp3-static.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\Release\paho-mqttpp3-static.lib
5>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
5>async_consume.cpp
10>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
7>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
12>------ Build started: Project: rpc_math_cli, Configuration: Release x64 ------
7>async_publish_time.cpp
10>mqttpp_chat.cpp
6>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
12>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
8>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
12>rpc_math_cli.cpp
6>async_publish.cpp
9>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
8>async_subscribe.cpp
11>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
9>data_publish.cpp
11>pub_speed_test.cpp
9>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\samples\data_publish.cpp(108,44): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
5>async_consume.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\async_consume.exe
13>------ Build started: Project: rpc_math_srvr, Configuration: Release x64 ------
7>async_publish_time.obj : error LNK2019: unresolved external symbol "private: static struct MQTTAsync_createOptions const mqtt::create_options::DFLT_C_STRUCT" (?DFLT_C_STRUCT@create_options@mqtt@@0UMQTTAsync_createOptions@@b) referenced in function main
7>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\async_publish_time.exe : fatal error LNK1120: 1 unresolved externals
7>Done building project "async_publish_time.vcxproj" -- FAILED.
14>------ Build started: Project: sync_consume, Configuration: Release x64 ------
10>mqttpp_chat.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\mqttpp_chat.exe
13>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
15>------ Build started: Project: sync_publish, Configuration: Release x64 ------
8>async_subscribe.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\async_subscribe.exe
13>rpc_math_srvr.cpp
14>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
16>------ Build started: Project: topic_publish, Configuration: Release x64 ------
15>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
6>async_publish.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\async_publish.exe
16>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/src/samples/CMakeLists.txt
14>sync_consume.cpp
15>sync_publish.cpp
12>rpc_math_cli.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\rpc_math_cli.exe
9>data_publish.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\data_publish.exe
16>topic_publish.cpp
9>Done building project "data_publish.vcxproj".
13>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(71,8): warning C4834: discarding return value of function with 'nodiscard' attribute
13>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(74,8): warning C4834: discarding return value of function with 'nodiscard' attribute
13>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(81,8): warning C4834: discarding return value of function with 'nodiscard' attribute
11>pub_speed_test.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\pub_speed_test.exe
14>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(71,8): warning C4834: discarding return value of function with 'nodiscard' attribute
14>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(74,8): warning C4834: discarding return value of function with 'nodiscard' attribute
14>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(81,8): warning C4834: discarding return value of function with 'nodiscard' attribute
15>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(71,8): warning C4834: discarding return value of function with 'nodiscard' attribute
15>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(74,8): warning C4834: discarding return value of function with 'nodiscard' attribute
15>C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\src\mqtt/client.h(81,8): warning C4834: discarding return value of function with 'nodiscard' attribute
16>topic_publish.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\topic_publish.exe
14>sync_consume.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\sync_consume.exe
14>Done building project "sync_consume.vcxproj".
15>sync_publish.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\sync_publish.exe
15>Done building project "sync_publish.vcxproj".
13>rpc_math_srvr.vcxproj -> C:\Users\Usuario\Desktop\VDB\dependencias\paho.mqtt.cpp\build\src\samples\Release\rpc_math_srvr.exe
13>Done building project "rpc_math_srvr.vcxproj".
17>------ Build started: Project: ALL_BUILD, Configuration: Release x64 ------
17>Building Custom Rule C:/Users/Usuario/Desktop/VDB/dependencias/paho.mqtt.cpp/CMakeLists.txt
========== Build: 16 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

@fpagliughi
Copy link
Contributor

OK. Thanks. I haven't tried this on Windows yet. I'll have a look and get it fixed.

@GiuServ
Copy link

GiuServ commented Nov 16, 2020

I have the same problem, on windows too.

unresolved external symbol "private: static struct MQTTAsync_createOptions const mqtt::create_options::DFLT_C_STRUCT" (?DFLT_C_STRUCT@create_options@mqtt@@0UMQTTAsync_createOptions@@B)

@fpagliughi
Copy link
Contributor

I just tried this and it worked for me. So I'm not seeing the problem.

The missing struct is (the only thing) defined in create_options.cpp:
https://github.com/eclipse/paho.mqtt.cpp/blob/076fc9977d07c25fa9fef1e19026d8be069c8e94/src/create_options.cpp#L24-L25

The source file is included in CMake:
https://github.com/eclipse/paho.mqtt.cpp/blob/076fc9977d07c25fa9fef1e19026d8be069c8e94/src/CMakeLists.txt#L48

And when I run CMake, the source file is listed in the src/paho-cpp-objs.vcxproj file that it produces:

...
    <ClCompile Include="K:\mqtt\paho-mqttpp\src\async_client.cpp" />
    <ClCompile Include="K:\mqtt\paho-mqttpp\src\client.cpp" />
    <ClCompile Include="K:\mqtt\paho-mqttpp\src\connect_options.cpp" />
    <ClCompile Include="K:\mqtt\paho-mqttpp\src\create_options.cpp" />          <--- ***
    <ClCompile Include="K:\mqtt\paho-mqttpp\src\disconnect_options.cpp" />
...

Sorry, I'm not much of a Windows programmer. Do you have any ideas? Are all these present on your local machines?

@fpagliughi
Copy link
Contributor

Has this been resolved?

@GiuServ
Copy link

GiuServ commented Dec 9, 2020

For my application i made a workaround, since everything compiles good but something wrong happends when using mqtt.cpp inside my application.
I edited the MQTTAsync_send function in MQTTAsync.c (https://github.com/eclipse/paho.mqtt.c/blob/master/src/MQTTAsync.c) changing this part:

if (m->createOptions == NULL) rc = MQTTASYNC_DISCONNECTED; else if (m->createOptions->sendWhileDisconnected == 0) rc = MQTTASYNC_DISCONNECTED; else if (m->shouldBeConnected == 0 && (m->createOptions->struct_version < 2 || m->createOptions->allowDisconnectedSendAtAnyTime == 0)) rc = MQTTASYNC_DISCONNECTED;

with this:

if (m->shouldBeConnected == 0 && m->createOptions != NULL && (m->createOptions->struct_version < 2 || m->createOptions->allowDisconnectedSendAtAnyTime == 0)) rc = MQTTASYNC_DISCONNECTED;

Obviously this solution is good just for me since i wanted to send messages while disconnected.

Have you changed/fixed something? Because i can try to update the sources and try to recompile.

@zhenhua10
Copy link

src\mqtt\create_options.h The DFLT_C_STRUCT problem of line 58 , I am modifying the 40 line “MQTTAsync_createOptions DFLT_C_STRUCT = MQTTAsync_createOptions_initializer;” and deleting "create"_ options.cpp "24 line const MQTTAsync_createOptions create_options::DFLT_C_STRUCT = MQTTAsync_createOptions_initializer;

@MikeMakes
Copy link
Author

Hi, sorry for not posting again, this issue was related to a client PC which I lost access. I think we workarounded it using another version of VScode.

Later I tried again in another system with VScode 2019 and it worked, the only difference I can think of was the system localization being the one who works USA english and the broken one SPAIN spanish I dont know how this could be related but I have faced problems in VScode with other libs bc of this.

@phuongtran7
Copy link

I just got the same problem when installing 1.2.0 from Vcpkg and using VS19 16.9.3. Building the library works just fine but whenever I use the mqtt::create_options_builder, the above error showed up. I've not tried building the library myself as I want Vcpkg to manage everything for me. Is there any work around for this?

@GiuServ
Copy link

GiuServ commented Jul 12, 2021

I retried it today, with updated source of mqtt and mqtccpp.
I can build from sources, but when using mqtt::create_options_builder() the problem is still here.
I both tried with vs2017 and vs2019.

@GiuServ
Copy link

GiuServ commented Jul 13, 2021

src\mqtt\create_options.h The DFLT_C_STRUCT problem of line 58 , I am modifying the 40 line “MQTTAsync_createOptions DFLT_C_STRUCT = MQTTAsync_createOptions_initializer;” and deleting "create"_ options.cpp "24 line const MQTTAsync_createOptions create_options::DFLT_C_STRUCT = MQTTAsync_createOptions_initializer;

With this solution it works.

@ultrahabbit
Copy link

I have encountered the same problem with Visual Studio 2019 for 2 projects: unit_tests and async_public_time. Obviously, the 2 projects are less the input library paho-cpp-objs.lib. After adding the paho-cpp-objs.lib, 2 projects are built successfully.

Additional, unit_tests project required use C++20 language to build.

Hope the developer modify the configure file of CMake for the above information.

@artemiuzzz
Copy link

The issue is still reproduced, in my case helped moving ctor from src\mqtt\create_options.h to cpp file:

create_options::create_options() : opts_( DFLT_C_STRUCT )
{}

qintxwd added a commit to qintxwd/paho.mqtt.cpp that referenced this issue Sep 4, 2023
@fpagliughi
Copy link
Contributor

^^^ OK. I will do what @artemiuzzz suggests and move the constructor out of the header file and into the .cpp file.

@fpagliughi fpagliughi added the fix added A fix has been pushed to the repo and is being tested label Nov 15, 2023
@fpagliughi fpagliughi self-assigned this Nov 15, 2023
@fpagliughi fpagliughi added this to the v1.3 milestone Nov 15, 2023
@fpagliughi
Copy link
Contributor

I assume the update fixes it for everyone. It not, please feel free to reopen this issue.

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

No branches or pull requests

7 participants