Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking on Windows with minGW-x64 #68

Open
stefphd opened this issue Jul 13, 2022 · 5 comments
Open

Linking on Windows with minGW-x64 #68

stefphd opened this issue Jul 13, 2022 · 5 comments
Milestone

Comments

@stefphd
Copy link

stefphd commented Jul 13, 2022

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

  • libsockpp.a for Linux
  • sockpp-static.lib for Windows

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):

  • In Linux all works ok using g++ -I./include -o tcp6echo tcp6echo.cpp -L./lib -lsockpp
  • In Windows with minGW-x64 issue occurs using g++ -I./include -o tcp6echo tcp6echo.cpp -L./lib -l:sockpp-static.lib
@stefphd stefphd changed the title Linking in Windows with minGW-x64 Linking on Windows with minGW-x64 Jul 13, 2022
@fpagliughi fpagliughi added this to the v0.8.1 milestone Jan 18, 2023
@fpagliughi fpagliughi modified the milestones: v0.8.1, v0.9 Jan 30, 2023
@LukeTheEngineer
Copy link

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

@wangyx1107
Copy link

wangyx1107 commented Sep 1, 2023

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
Copy link

wangyx1107 commented Sep 1, 2023

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
Copy link

wangyx1107 commented Sep 2, 2023

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants