skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.84k stars 209 forks source link

Undeclared uv enum values. #227

Closed Yuhanun closed 3 years ago

Yuhanun commented 3 years ago

Hello,

I'm currently trying to build the library:

#include <uvw.hpp>
#include <memory>

void listen(uvw::Loop &loop) {
    std::shared_ptr<uvw::TCPHandle> tcp = loop.resource<uvw::TCPHandle>();

    tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
        std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();

        client->on<uvw::CloseEvent>([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TCPHandle &) { ptr->close(); });
        client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); });

        srv.accept(*client);
        client->read();
    });

    tcp->bind("127.0.0.1", 4242);
    tcp->listen();
}

void conn(uvw::Loop &loop) {
    auto tcp = loop.resource<uvw::TCPHandle>();

    tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* handle errors */ });

    tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &tcp) {
        auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
        tcp.write(std::move(dataWrite), 2);
        tcp.close();
    });

    tcp->connect(std::string{"127.0.0.1"}, 4242);
}

int main() {
    auto loop = uvw::Loop::getDefault();
    listen(*loop);
    conn(*loop);
    loop->run();
}

However, the following error is thrown:

In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:1:
In file included from ../thirdparty/uvw/src/uvw/async.h:6:
In file included from ../thirdparty/uvw/src/uvw/handle.hpp:9:
In file included from ../thirdparty/uvw/src/uvw/resource.hpp:8:
In file included from ../thirdparty/uvw/src/uvw/underlying_type.hpp:8:
../thirdparty/uvw/src/uvw/loop.h:43:17: error: use of undeclared identifier 'UV_METRICS_IDLE_TIME'
    IDLE_TIME = UV_METRICS_IDLE_TIME
                ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:1:
In file included from ../thirdparty/uvw/src/uvw/async.h:6:
In file included from ../thirdparty/uvw/src/uvw/handle.hpp:9:
In file included from ../thirdparty/uvw/src/uvw/resource.hpp:8:
In file included from ../thirdparty/uvw/src/uvw/underlying_type.hpp:8:
In file included from ../thirdparty/uvw/src/uvw/loop.h:430:
../thirdparty/uvw/src/uvw/loop.cpp:101:17: error: use of undeclared identifier 'uv_metrics_idle_time'
    return Time{uv_metrics_idle_time(loop.get())};
                ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:6:
../thirdparty/uvw/src/uvw/fs.h:59:14: error: use of undeclared identifier 'UV_FS_LUTIME'
    LUTIME = UV_FS_LUTIME
             ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:6:
In file included from ../thirdparty/uvw/src/uvw/fs.h:1459:
../thirdparty/uvw/src/uvw/fs.cpp:316:23: error: use of undeclared identifier 'uv_fs_lutime'
    cleanupAndInvoke(&uv_fs_lutime, parent(), get(), path.data(), atime.count(), mtime.count(), &fsGenericCallback<Type::LUTIME>);
                      ^
../thirdparty/uvw/src/uvw/fs.cpp:322:27: error: use of undeclared identifier 'uv_fs_lutime'
    cleanupAndInvokeSync(&uv_fs_lutime, parent(), req, path.data(), atime.count(), mtime.count());
                          ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:22:
In file included from ../thirdparty/uvw/src/uvw/timer.h:113:
../thirdparty/uvw/src/uvw/timer.cpp:48:17: error: use of undeclared identifier 'uv_timer_get_due_in'; did you mean 'uv_timer_get_repeat'?
    return Time{uv_timer_get_due_in(get())};
                ^~~~~~~~~~~~~~~~~~~
                uv_timer_get_repeat
/usr/include/uv.h:853:20: note: 'uv_timer_get_repeat' declared here
UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
                   ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:24:
../thirdparty/uvw/src/uvw/udp.h:49:22: error: use of undeclared identifier 'UV_UDP_MMSG_CHUNK'
    UDP_MMSG_CHUNK = UV_UDP_MMSG_CHUNK,
                     ^
../thirdparty/uvw/src/uvw/udp.h:50:21: error: use of undeclared identifier 'UV_UDP_MMSG_FREE'
    UDP_MMSG_FREE = UV_UDP_MMSG_FREE,
                    ^
../thirdparty/uvw/src/uvw/udp.h:51:20: error: use of undeclared identifier 'UV_UDP_RECVMMSG'
    UDP_RECVMMSG = UV_UDP_RECVMMSG
                   ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:1:
In file included from ../thirdparty/uvw/src/uvw/async.h:6:
In file included from ../thirdparty/uvw/src/uvw/handle.hpp:6:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/utility:70:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_pair.h:59:
In file included from /bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/move.h:57:
/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/type_traits:2957:5: error: no type named 'type' in 'std::invoke_result<int (*)(uv_loop_s *, uv_fs_s *, int, double, double, void (*)(uv_fs_s *)), uv_loop_s *, uv_fs_s *, char *, double, double, void (*)(uv_fs_s *)>'
    using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
    ^~~~~
../thirdparty/uvw/src/uvw/request.hpp:38:42: note: in instantiation of template type alias 'invoke_result_t' requested here
        if constexpr(std::is_void_v<std::invoke_result_t<F, Args...>>) {
                                         ^
../thirdparty/uvw/src/uvw/fs.h:406:15: note: in instantiation of function template specialization 'uvw::Request<uvw::FsReq, uv_fs_s>::invoke<int (*)(uv_loop_s *, uv_fs_s *, int, double, double, void (*)(uv_fs_s *)), uv_loop_s *, uv_fs_s *, char *, double, double, void (*)(uv_fs_s *)>' requested here
        this->invoke(std::forward<Args>(args)...);
              ^
../thirdparty/uvw/src/uvw/fs.cpp:316:5: note: in instantiation of function template specialization 'uvw::FsRequest<uvw::FsReq>::cleanupAndInvoke<int (*)(uv_loop_s *, uv_fs_s *, int, double, double, void (*)(uv_fs_s *)), uv_loop_s *, uv_fs_s *, char *, double, double, void (*)(uv_fs_s *)>' requested here
    cleanupAndInvoke(&uv_fs_lutime, parent(), get(), path.data(), atime.count(), mtime.count(), &fsGenericCallback<Type::LUTIME>);
    ^
In file included from ../main.cpp:1:
In file included from ../thirdparty/uvw/src/uvw.hpp:6:
../thirdparty/uvw/src/uvw/fs.h:412:28: error: cannot initialize a parameter of type 'int' with an rvalue of type 'char *'
        std::forward<F>(f)(std::forward<Args>(args)..., nullptr);
                           ^~~~~~~~~~~~~~~~~~~~~~~~
../thirdparty/uvw/src/uvw/fs.cpp:322:5: note: in instantiation of function template specialization 'uvw::FsRequest<uvw::FsReq>::cleanupAndInvokeSync<int (*)(uv_loop_s *, uv_fs_s *, int, double, double, void (*)(uv_fs_s *)), uv_loop_s *, uv_fs_s *&, char *, double, double>' requested here
    cleanupAndInvokeSync(&uv_fs_lutime, parent(), req, path.data(), atime.count(), mtime.count());
    ^
11 errors generated.
[80/120] Building CXX object thirdparty/uvw/test/CMakeFiles/main.dir/main.cpp.o

This code example is quite literally the code from your readme.

Thank you

stefanofiorentino commented 3 years ago

Ciao @Yuhanun, can you show us the cmake configuration flags?

stefanofiorentino commented 3 years ago

@Yuhanun any news on this, I'll go closing it as seems just a misconfiguration in cmake options and/or a different version of libuv installed in discoverable/system path. Feel free to reopen it if you're still experiencing this issue.

Yuhanun commented 3 years ago

Issue persis, ill send configuration flags later today.

stefanofiorentino commented 3 years ago

@Yuhanun the missing flags in your error output have been introduced/changed during last three months. So consider removing any other version installed and discoverable by CMake from your system. Hope this helps.