admin管理员组文章数量:1122832
I know what LNK1169 stands for. So the point is not what this error is, but why it happens, especially since the duplicate defined function is a destructor of an stl template.
The full error is below:
datachannel.lib(datachannel.dll) : error LNK2005: "public: __cdecl std::vector<enum std::byte,class std::allocator<enum std::byte> >::~vector<enum std::byte,class std::allocator<enum std::byte> >(void)" (??1?$vector@W4byte@std@@V?$allocator@W4byte@std@@@2@@std@@QEAA@XZ) already defined in media_source.obj [D:\projects\conference-go-client\build\test-uvc.vcxproj]
[build] D:\projects\conference-go-client\build\Debug\test-uvc.exe : fatal error LNK1169: Find one or more symbols with multiple definitions
In media_source.obj I could find code related to std::vector<std::byte>
simplified as follows
// media_source.hpp
using media_packet_t = std::vector<std::byte>;
using media_packet_ptr_t = std::shared_ptr<media_packet_t>;
class MediaReceiver
{
public:
virtual ~MediaReceiver() = default;
virtual auto request_pkt(close_chan closer) -> asio::awaitable<media_packet_ptr_t> = 0;
virtual void request_key_frame() = 0;
};
// media_source.cpp
struct MediaReceiverImpl
{
MediaReceiverImpl(){}
auto request_pkt(close_chan closer) -> asio::awaitable<media_packet_ptr_t>;
void request_key_frame();
};
struct MediaReceiverWrapper : public MediaReceiver
{
using impl_t = unique_smart_node<MediaReceiverImpl>;
unique_smart_node<MediaReceiverImpl> m_impl;
MediaReceiverWrapper(impl_t && impl): m_impl(std::move(impl)) {}
~MediaReceiverWrapper() = default;
auto request_pkt(close_chan closer) -> asio::awaitable<media_packet_ptr_t> override
{
return m_impl->request_pkt(std::move(closer));
}
void request_key_frame() override
{
m_impl->request_key_frame();
}
};
The std::vector<std::byte>
used in libdatachannel should refer to the
namespace rtc {
using std::byte;
using binary = std::vector<byte>;
};
In addition, the above error only occurs on windows platform, not on linux with gcc.
Update:
After change my own defined media_packet_t to rtc::binary, the error disappeared. But I'm still trying to figure out why.
// using media_packet_t = std::vector<std::byte>;
// using media_packet_ptr_t = std::shared_ptr<media_packet_t>;
using media_packet_t = rtc::binary;
using media_packet_ptr_t = std::shared_ptr<media_packet_t>;
I know what LNK1169 stands for. So the point is not what this error is, but why it happens, especially since the duplicate defined function is a destructor of an stl template.
The full error is below:
datachannel.lib(datachannel.dll) : error LNK2005: "public: __cdecl std::vector<enum std::byte,class std::allocator<enum std::byte> >::~vector<enum std::byte,class std::allocator<enum std::byte> >(void)" (??1?$vector@W4byte@std@@V?$allocator@W4byte@std@@@2@@std@@QEAA@XZ) already defined in media_source.obj [D:\projects\conference-go-client\build\test-uvc.vcxproj]
[build] D:\projects\conference-go-client\build\Debug\test-uvc.exe : fatal error LNK1169: Find one or more symbols with multiple definitions
In media_source.obj I could find code related to std::vector<std::byte>
simplified as follows
// media_source.hpp
using media_packet_t = std::vector<std::byte>;
using media_packet_ptr_t = std::shared_ptr<media_packet_t>;
class MediaReceiver
{
public:
virtual ~MediaReceiver() = default;
virtual auto request_pkt(close_chan closer) -> asio::awaitable<media_packet_ptr_t> = 0;
virtual void request_key_frame() = 0;
};
// media_source.cpp
struct MediaReceiverImpl
{
MediaReceiverImpl(){}
auto request_pkt(close_chan closer) -> asio::awaitable<media_packet_ptr_t>;
void request_key_frame();
};
struct MediaReceiverWrapper : public MediaReceiver
{
using impl_t = unique_smart_node<MediaReceiverImpl>;
unique_smart_node<MediaReceiverImpl> m_impl;
MediaReceiverWrapper(impl_t && impl): m_impl(std::move(impl)) {}
~MediaReceiverWrapper() = default;
auto request_pkt(close_chan closer) -> asio::awaitable<media_packet_ptr_t> override
{
return m_impl->request_pkt(std::move(closer));
}
void request_key_frame() override
{
m_impl->request_key_frame();
}
};
The std::vector<std::byte>
used in libdatachannel should refer to the
namespace rtc {
using std::byte;
using binary = std::vector<byte>;
};
In addition, the above error only occurs on windows platform, not on linux with gcc.
Update:
After change my own defined media_packet_t to rtc::binary, the error disappeared. But I'm still trying to figure out why.
// using media_packet_t = std::vector<std::byte>;
// using media_packet_ptr_t = std::shared_ptr<media_packet_t>;
using media_packet_t = rtc::binary;
using media_packet_ptr_t = std::shared_ptr<media_packet_t>;
Share
Improve this question
edited Nov 21, 2024 at 17:28
vipcxj
asked Nov 21, 2024 at 16:35
vipcxjvipcxj
1,0387 silver badges11 bronze badges
8
|
Show 3 more comments
1 Answer
Reset to default 0I found the key is "rtc/track.hpp" in libdatachannel
class RTC_CPP_EXPORT Track final : private CheshireCat<impl::Track>, public Channel {
public:
void onFrame(std::function<void(binary data, FrameInfo frame)> callback);
};
If I include this header, the issue disappeared. It seems that RTC_CPP_EXPORT
is the key. it is __declspec(dllimport)
on windows, but nothing on linux. So the issue only happen on windows.
I'm not sure exactly why yet, but it should have something to do with it
本文标签: cerror LNK1169 of stdvectorltstdbytegt destructorStack Overflow
版权声明:本文标题:c++ - error LNK1169 of std::vector<std::byte> destructor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308846a1933805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
media_packet_ptr_t
supposed to solve? – Some programmer dude Commented Nov 21, 2024 at 16:45media_source
is usingstd::vector<std::byte>
but libdatachannel is usingstd::vector<byte>
, is it possible that libdatachannel has redefined whatbyte
is and is conflicting with the standardbyte
? – Remy Lebeau Commented Nov 21, 2024 at 16:49