drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.63k stars 1.12k forks source link

drogon with BUILD_EXAMPLES=ON does not link on versions 1.9.7 & 1.9.8 (possibly also 1.9.6) #2208

Open eniv opened 2 weeks ago

eniv commented 2 weeks ago

Looks like an issue with the async_stream example:

[ 79%] Linking CXX executable async_stream
/usr/bin/ld: CMakeFiles/async_stream.dir/async_stream/main.cc.o: in function `void drogon::internal::HttpBinder<main::{lambda(std::shared_ptr<drogon::HttpRequest> const&, std::shared_ptr<drogon::RequestStream>&&, std::function<void (std::shared_ptr<drogon::HttpResponse> const&)>&&)#2}>::run<, 0ul, true, false>(std::deque<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::shared_ptr<drogon::HttpRequest> const&, std::function<void (std::shared_ptr<drogon::HttpResponse> const&)>&&) [clone .constprop.0] [clone .isra.0]':
main.cc:(.text+0x1086): undefined reference to `drogon::RequestStreamReader::newReader(std::function<void (char const*, unsigned long)>, std::function<void (std::__exception_ptr::exception_ptr)>)'
/usr/bin/ld: CMakeFiles/async_stream.dir/async_stream/RequestStreamExampleCtrl.cc.o: in function `RequestStreamExampleCtrl::stream_upload(std::shared_ptr<drogon::HttpRequest> const&, std::shared_ptr<drogon::RequestStream>&&, std::function<void (std::shared_ptr<drogon::HttpResponse> const&)>&&) const':
RequestStreamExampleCtrl.cc:(.text._ZNK24RequestStreamExampleCtrl13stream_uploadERKSt10shared_ptrIN6drogon11HttpRequestEEOS0_INS1_13RequestStreamEEOSt8functionIFvRKS0_INS1_12HttpResponseEEEE[_ZNK24RequestStreamExampleCtrl13stream_uploadERKSt10shared_ptrIN6drogon11HttpRequestEEOS0_INS1_13RequestStreamEEOSt8functionIFvRKS0_INS1_12HttpResponseEEEE]+0x260): undefined reference to `drogon::RequestStreamReader::newMultipartReader(std::shared_ptr<drogon::HttpRequest> const&, std::function<void (drogon::MultipartHeader)>, std::function<void (char const*, unsigned long)>, std::function<void (std::__exception_ptr::exception_ptr)>)'
collect2: error: ld returned 1 exit status
make[2]: *** [examples/CMakeFiles/async_stream.dir/build.make:119: examples/async_stream] Error 1
make[1]: *** [CMakeFiles/Makefile2:574: examples/CMakeFiles/async_stream.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Am I missing something?

fantasy-peak commented 2 weeks ago

Are there other versions of drogon on your system?

eniv commented 2 weeks ago

No, I just checked. Or to be more accurate, not installed. There is a very old one in a local trash folder. I'm pretty sure the examples are linked against the version of libdrogon being built.

fantasy-peak commented 2 weeks ago

Maybe you could empty the build directory and rebuild

eniv commented 2 weeks ago

Thanks for the suggestion. I've already tried that. In order to prove to myself that I'm linking against the correct version of libdrogon, I checked the dependencies of a different example which did not fail linking. As you can see in the screenshot below, it links against libdrogon1.9.8: image

Also, I should have noted that earlier. I'm using g++12.3

eniv commented 2 weeks ago

Looks like DROGON_EXPORT is missing in RequestStream.h for the RequestStreamReader class. Once I add it, the linker is satisfied

fantasy-peak commented 2 weeks ago

Thanks for the suggestion. I've already tried that. In order to prove to myself that I'm linking against the correct version of libdrogon, I checked the dependencies of a different example which did not fail linking. As you can see in the screenshot below, it links against libdrogon1.9.8: image

Also, I should have noted that earlier. I'm using g++12.3

It's very strange,I can compile by using gcc13.1 14.2.

eniv commented 2 weeks ago

Something must have changed after 12.3 with the visibility attribute.

hwc0919 commented 1 week ago

It's strange. I'm using gcc 11.1 and it works fine.

fantasy-peak commented 1 week ago

It's strange. I'm using gcc 11.1 and it works fine.

maybe only gcc12.not work

hwc0919 commented 1 week ago

Maybe it's because the shared lib. I'm using static lib. But shared lib linkage is also tested in ci.