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

There seems no definition of Platform::free and so on for macOS. #4

Closed
shinyaohtani opened this issue Feb 16, 2021 · 18 comments
Closed
Labels
bug Something isn't working

Comments

@shinyaohtani
Copy link

my clang says "Undefined symbols". Does eMQTT5 support macOS?

Undefined symbols for architecture x86_64:
  "Platform::free(void*, bool)", referenced from:
      Network::Client::MQTTv5::connectTo(char const*, unsigned short, bool, unsigned short, bool, char const*, Protocol::MQTT::Common::DynamicBinDataView const*, Protocol::MQTT::V5::WillMessage*, Protocol::MQTT::V5::QualityOfServiceDelivery, bool, Protocol::MQTT::V5::Properties*) in libeMQTT5.a(MQTTClient.cpp.o)
      Network::Client::MQTTv5::Impl::Impl(char const*, Network::Client::MessageReceived*, Protocol::MQTT::Common::DynamicBinDataView const*) in libeMQTT5.a(MQTTClient.cpp.o)
      Protocol::MQTT::Common::DynamicString::readFrom(unsigned char const*, unsigned int) in libeMQTT5.a(MQTTClient.cpp.o)
      Network::Client::MQTTv5::Impl::~Impl() in libeMQTT5.a(MQTTClient.cpp.o)
  "Platform::malloc(unsigned long, bool)", referenced from:
      Network::Client::MQTTv5::connectTo(char const*, unsigned short, bool, unsigned short, bool, char const*, Protocol::MQTT::Common::DynamicBinDataView const*, Protocol::MQTT::V5::WillMessage*, Protocol::MQTT::V5::QualityOfServiceDelivery, bool, Protocol::MQTT::V5::Properties*) in libeMQTT5.a(MQTTClient.cpp.o)
      Network::Client::MQTTv5::Impl::Impl(char const*, Network::Client::MessageReceived*, Protocol::MQTT::Common::DynamicBinDataView const*) in libeMQTT5.a(MQTTClient.cpp.o)
  "Platform::realloc(void*, unsigned long)", referenced from:
      Protocol::MQTT::Common::DynamicString::readFrom(unsigned char const*, unsigned int) in libeMQTT5.a(MQTTClient.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@X-Ryl669
Copy link
Owner

I was developing on a Mac when I wrote this, so it should work. Can you send me your CMake's build configuration?

@X-Ryl669
Copy link
Owner

X-Ryl669 commented Feb 16, 2021

The definition of the 3 methods are in eMQTT5/tests/ClassPath/src/Posix.cpp.
And the file is listed to be built when the platform is not Windows:

add_executable(MQTTc 
    MQTTc.cpp
    ClassPath/src/Address.cpp
    ClassPath/src/bstrwrap.cpp
    ClassPath/src/HashKey.cpp
    ClassPath/src/Lock.cpp
    ClassPath/src/Logger.cpp
    ClassPath/src/Strings.cpp
    ClassPath/src/Time.cpp
    ClassPath/src/Socket.cpp
    ClassPath/src/LinuxSpecific.cpp
    $<$<PLATFORM_ID:WIN32>:ClassPath/src/Windows.cpp>
    $<$<NOT:$<PLATFORM_ID:WIN32>>:ClassPath/src/Posix.cpp>

    ClassPath/src/bstrlib.c)

@X-Ryl669
Copy link
Owner

Can you add a -D_POSIX to your CXX flags to see if it works ? I wonder if they removed the preprocessor macro recently.

@shinyaohtani
Copy link
Author

Thank you for very quick reply! Now I'll try -D_POSIX.

@shinyaohtani
Copy link
Author

I added -D_POSIX. but result was same.

I indicate eMQTT5 as a link target from my CMakeLists.txt. Is it correct? What is a correct target name?
Is it written in the document below? I can't read it because URL is collapse.

API Documentation
You'll find the client API documentation here.
https://blog.cyril.by/en/documentation/emqtt5

@shinyaohtani
Copy link
Author

According to my cmake knowledge, it seems that only one source file is compiled for the target eMQTT5 which doesn't include eMQTT5/tests/ClassPath/src/Posix.cpp.

add_library(eMQTT5 src/Network/Clients/MQTTClient.cpp)

@shinyaohtani
Copy link
Author

shinyaohtani commented Feb 16, 2021

There seems no definition of Platform::free and so on for library eMQTT5. Excuse me, could you please tell me the proper way to write my cmake to link eMQTT5 as a library. 🙏

now i just write like:

TARGET_LINK_LIBRARIES(myProj
  eMQTT5
)

@X-Ryl669
Copy link
Owner

I've fixed the URL. The library shouldn't need platform code, only the test code does. Let me check...

@shinyaohtani
Copy link
Author

I just use Network::Client::MQTTv5 as a library. I include #include <Network/Clients/MQTT.hpp> from my code.

@X-Ryl669
Copy link
Owner

X-Ryl669 commented Feb 16, 2021

Can you try with latest master b197dac ? It should have fixed the issue.

@X-Ryl669 X-Ryl669 added the bug Something isn't working label Feb 16, 2021
@shinyaohtani
Copy link
Author

shinyaohtani commented Feb 16, 2021

I tried but same. Only src/Network/Clients/MQTTClient.cpp is compiled for libeMQTT5.a

Is this your modification correct?

$<$<PLATFORM_ID:WIN32>:src/Platform/Windows.cpp>

Undefined symbols for architecture x86_64:
  "Platform::free(void*, bool)", referenced from:
      Network::Client::MQTTv5::connectTo(char const*, unsigned short, bool, unsigned short, bool, char const*, Protocol::MQTT::Common::DynamicBinDataView const*, Protocol::MQTT::V5::WillMessage*, Protocol::MQTT::V5::QualityOfServiceDelivery, bool, Protocol::MQTT::V5::Properties*) in libeMQTT5.a(MQTTClient.cpp.o)
      Network::Client::MQTTv5::Impl::Impl(char const*, Network::Client::MessageReceived*, Protocol::MQTT::Common::DynamicBinDataView const*) in libeMQTT5.a(MQTTClient.cpp.o)
      Protocol::MQTT::Common::DynamicString::readFrom(unsigned char const*, unsigned int) in libeMQTT5.a(MQTTClient.cpp.o)
      Network::Client::MQTTv5::Impl::~Impl() in libeMQTT5.a(MQTTClient.cpp.o)
  "Platform::malloc(unsigned long, bool)", referenced from:
      Network::Client::MQTTv5::connectTo(char const*, unsigned short, bool, unsigned short, bool, char const*, Protocol::MQTT::Common::DynamicBinDataView const*, Protocol::MQTT::V5::WillMessage*, Protocol::MQTT::V5::QualityOfServiceDelivery, bool, Protocol::MQTT::V5::Properties*) in libeMQTT5.a(MQTTClient.cpp.o)
      Network::Client::MQTTv5::Impl::Impl(char const*, Network::Client::MessageReceived*, Protocol::MQTT::Common::DynamicBinDataView const*) in libeMQTT5.a(MQTTClient.cpp.o)
  "Platform::realloc(void*, unsigned long)", referenced from:
      Protocol::MQTT::Common::DynamicString::readFrom(unsigned char const*, unsigned int) in libeMQTT5.a(MQTTClient.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@X-Ryl669
Copy link
Owner

Can you try to apply this patch on the latest master and try to build it (it should fail, please post the log):

diff --git a/lib/include/Platform/Platform.hpp b/lib/include/Platform/Platform.hpp
index 30d15eb..322e3e8 100644
--- a/lib/include/Platform/Platform.hpp
+++ b/lib/include/Platform/Platform.hpp
@@ -49,28 +49,27 @@ namespace Platform
     /** Get the current process name.
         This does not rely on remembering the argv[0] since this does not exists on Windows.
         This returns the name of executable used to run the process */
-    inline const char * getProcessName() {
+    inline const char * getProcessName()^M
     {
         static char * processName = NULL;
         if (!processName)
         {
-#ifdef _LINUX
+  #ifdef _LINUX^M
             FILE * f = fopen("/proc/self/cmdline", "r");
             if (f) {
                 char buffer[256];
                 processName = strdup(fgets(buffer, 256, f));
                 fclose(f);
             }
-#elif defined(_MAC)
+  #elif defined(_MAC)^M
             processName = strdup(getprogname());
-#else
+  #else^M
             return "program";
-#endif
+  #endif^M
         }
         return processName;
     }
-
-return "this_program"; } // Poor workaround to avoid so many difference between platforms
+#error here^M
 #else
     /** The simple malloc overload.
         If you need to use another allocator, you should define this method

@shinyaohtani
Copy link
Author

🙏 Could you push it to a branch?

@X-Ryl669
Copy link
Owner

In the latest master, I've removed Posix.cpp file since it was useless (even for tests). Yet, it seems the compiler tries to build it anyway. It's strange.

@X-Ryl669
Copy link
Owner

X-Ryl669 commented Feb 16, 2021

Try the branch called "badStuff", run rm -rf build && mkdir build then rerun ccmake .. in the build directory, then make and post output. It should fail building with "error here" issues.

@shinyaohtani
Copy link
Author

shinyaohtani commented Feb 16, 2021

ok with my env, this is output for the branch 0cac22e

[  1%] Building CXX object common_libs/myLib/common_libs/eMQTT5/lib/CMakeFiles/eMQTT5.dir/src/Network/Clients/MQTTClient.cpp.o
cd ~/build/myProj/common_libs/myLib/common_libs/eMQTT5/lib && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DMQTTOnlyBSDSocket=1 -DMQTTUseTLS=0 -DMinimalFootPrint=1 -D_DEBUG=0 -I~/repos/external/eMQTT5/lib/include -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.15 -std=c++11 -o CMakeFiles/eMQTT5.dir/src/Network/Clients/MQTTClient.cpp.o -c ~/repos/external/eMQTT5/lib/src/Network/Clients/MQTTClient.cpp
In file included from ~/repos/external/eMQTT5/lib/src/Network/Clients/MQTTClient.cpp:2:
In file included from ~/repos/external/eMQTT5/lib/src/Network/Clients/../../../include/Network/Clients/MQTT.hpp:5:
~/repos/external/eMQTT5/lib/src/Network/Clients/../../../include/Network/Clients/MQTTConfig.hpp:89:9: warning: 
      Building eMQTT5 with flags: __Check__BSD [-W#pragma-messages]
#pragma message("Building eMQTT5 with flags: " CONF_AUTH CONF_DUMP CONF_VALID CONF_TLS CONF_SOCKET)
        ^
In file included from ~/repos/external/eMQTT5/lib/src/Network/Clients/MQTTClient.cpp:2:
In file included from ~/repos/external/eMQTT5/lib/src/Network/Clients/../../../include/Network/Clients/MQTT.hpp:8:
In file included from ~/repos/external/eMQTT5/lib/src/Network/Clients/../../../include/Network/Clients/../../Protocol/MQTT/MQTT.hpp:7:
~/repos/external/eMQTT5/lib/src/Network/Clients/../../../include/Network/Clients/../../Protocol/MQTT/../../Platform/Platform.hpp:72:2: error: 
      here
#error here
 ^
1 warning and 1 error generated.
make[2]: *** [common_libs/myLib/common_libs/eMQTT5/lib/CMakeFiles/eMQTT5.dir/src/Network/Clients/MQTTClient.cpp.o] Error 1
make[1]: *** [common_libs/myLib/common_libs/eMQTT5/lib/CMakeFiles/eMQTT5.dir/all] Error 2
make: *** [all] Error 2

What does this mean?

@shinyaohtani
Copy link
Author

Oh, link error was gone with master HEAD!! 1 hour ago, I tried it. it seems that it was my mistake. I'm sorry.
#4 (comment)

Now I can build it without any problems. Thank you.

@X-Ryl669
Copy link
Owner

Ok, great. The issue you experienced was because I was too fast pushing code that did not build. I've fixed up 5mn later but you've probably pulled in between. Glad it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants