cpp-linenoise icon indicating copy to clipboard operation
cpp-linenoise copied to clipboard

multiple definition errors on Windows (at link time)

Open bsergean opened this issue 4 years ago • 0 comments

I am getting errors like this when include libnoise.hpp in multiple source (cpp) files in my project (https://github.com/machinezone/IXWebSocket)

Example file -> https://github.com/machinezone/IXWebSocket/blob/ac9710d5d6e1c3dba1c681168cca39e358ab73ef/ws/ws_redis_cli.cpp

(?grm@ansi@linenoise@@3UGRM@12@A) already defined in ws_connect.obj [D:\a\IXWebSocket\IXWebSocket\build\ws\ws.vcxproj]
ws_redis_cli.obj : error LNK2005: "struct _COORD linenoise::ansi::SavePos" (?SavePos@ansi@linenoise@@3U_COORD@@A) already defined in ws_connect.obj [D:\a\IXWebSocket\IXWebSocket\build\ws\ws.vcxproj]
ws_redis_cli.obj : error LNK2005: "int linenoise::ansi::nCharInBuffer" (?nCharInBuffer@ansi@linenoise@@3HA) already defined in ws_connect.obj [D:\a\IXWebSocket\IXWebSocket\build\ws\ws.vcxproj]
ws_redis_cli.obj : error LNK2005: "wchar_t * linenoise::ansi::ChBuffer" (?ChBuffer@ansi@linenoise@@3PA_WA) already defined in ws_connect.obj [D:\a\IXWebSocket\IXWebSocket\build\ws\ws.vcxproj]

The way I solved it is by moving the body in an implementation file, but I wonder if there's a better way.

(fix => https://github.com/machinezone/IXWebSocket/commit/6ed8723d7d39406079dcf973e9e751f429d01b07)

bsergean avatar Jun 12 '20 01:06 bsergean