fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
792 stars 126 forks source link

Linking on Windows with minGW-x64 #68

Open stefphd opened 2 years ago

stefphd commented 2 years ago

I was able to create a static library in both Windows and Linux (using ArchLinux) following the README. Two files were generated:

Then I need to use the static library in another program, which is built using a Makefile. In Linux no issue occurs, while in Windows with minGW-x64 I received multiple errors like

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\ccvvpJbH.o:tcp6echo.cpp:(.text+0x176): undefined reference to `sockpp::operator<<(std::ostream&, sockpp::inet6_address const&)'

To reproduce the issue with the example tcp6echo (assuming headers in ./include and static library in ./lib):

LukeTheEngineer commented 1 year ago

I'm assuming this issue isn't solved yet.

wangyx1107 commented 1 year ago

I am facing the same issue when building 'example/tcpecho.cpp' with MinGW64-g++. Multiple linking errors were shown as 'undefined reference' even when given correct '-I -L -l' parameters after installation.

I assume that this is because the default building tool written in CMake configuration for windows is MSVC, and therefore the library generated is not fully compatible with MinGW.

Providing an alternative CMake configuration for MinGW-Windows may be able to solve the problem.

wangyx1107 commented 1 year ago

It turned out that the compatibility issue between MSVC and MinGW was the exact cause of the issue in my case.

To address the problem: When first executing CMake, simply add -G "MinGW Makefiles" to specify the generator. Like :

cmake -Bbuild -G "MinGW Makefiles" .

If you've already built it via MSVC before, you will have to clean the CMake cache by following the prompt given when you run the command above.

wangyx1107 commented 1 year ago

Sorry.

The issue re-occurs when it comes to static library which cannot be solved by rebuilding with MinGW. (The solution above works for .dll)

Maybe this is an issue that requires an update to fix.

fpagliughi commented 1 year ago

Hey. Sorry. I'm not a Windows programmer and have never used MinGW. So any help or suggestions would be appreciated, as would a PR if a solution is discovered that doesn't break the other platforms.