BewareMyPower opened a new issue, #107: URL: https://github.com/apache/pulsar-client-cpp/issues/107
### Search before asking - [X] I searched in the [issues](https://github.com/apache/pulsar-client-cpp/issues) and found nothing similar. ### Version It works for master branch, but you can also use the release here [x64-windows-static-Debug](https://github.com/streamnative/pulsar-client-cpp/suites/9150203394/artifacts/425759462) in [here](https://github.com/streamnative/pulsar-client-cpp/actions/runs/3403392007). Uncompress it to a directory, e.g. `D:\pulsar-cpp-debug`. ``` D:\pulsar-cpp-debug bin/pulsar.dll lib/pulsar.lib include/ ``` ### Minimal reproduce step CMakeLists.txt ```cmake cmake_minimum_required(VERSION 3.15) project("PulsarApp" CXX) set(PULSAR_ROOT "D:\\pulsar-cpp-debug") add_executable(PulsarApp main.cc) include_directories("${PULSAR_ROOT}/include") target_link_libraries(PulsarApp PRIVATE "${PULSAR_ROOT}/lib/pulsar.lib") set_property(TARGET PulsarApp PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") ``` main.cc ```c++ #include <pulsar/Client.h> using namespace pulsar; int main() { auto msg = MessageBuilder().setContent("hello").build(); std::cout << msg.getDataAsString() << std::endl; return 0; } ``` Then run the following commands in PowerShell ```PowerShell cmake -B build cmake --build build --config Debug cp D:\pulsar-cpp-debug\bin\pulsar.dll . .\build\Debug\PulsarApp.exe ``` ### What did you expect to see? "hello" is printed. ### What did you see instead?  ### Anything else? It looks like to be caused by the combination of static linking of 3rd party dependencies (`LINK_STATIC=ON`) and the `std::string` API compatibility. For example, the following example works well. ```c++ #include <assert.h> #include <pulsar/Client.h> using namespace pulsar; int main() { auto topic = "topic"; Client client("pulsar://172.24.101.226:6650"); Producer producer; assert(ResultOk == client.createProducer(topic, producer)); Consumer consumer; assert(ResultOk == client.subscribe(topic, "sub", consumer)); producer.send(MessageBuilder().setContent("msg").build()); Message msg; assert(ResultOk == consumer.receive(msg)); // NOTE: it's the same with the `getDataAsString()` implementation std::cout << std::string(static_cast<const char*>(msg.getData()), msg.getLength()) << std::endl; client.close(); } ``` ### Are you willing to submit a PR? - [X] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
