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

Automatic Lib Init (NetworkInitializer) is not working on MinGW #661

Closed
asari-fd opened this issue Jan 7, 2015 · 9 comments
Closed

Automatic Lib Init (NetworkInitializer) is not working on MinGW #661

asari-fd opened this issue Jan 7, 2015 · 9 comments

Comments

@asari-fd
Copy link
Contributor

asari-fd commented Jan 7, 2015

I'm writing a network client using Poco and MinGW.
It seems that I have to call Poco::Net::initializeNetwork() before calling any network-related functions, otherwise I get an exception like "DNS error: EAI: 10093", which means WSANOTINITIALISED (according to http://support.microsoft.com/kb/819124/) -- is it intended?

I think I'd be happy if I can always omit initializeNetwork() calls. Thanks.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty
$ dpkg -l | grep mingw32
ii  mingw32                           4.2.1.dfsg-2ubuntu1                      amd64        Minimalist GNU win32 (cross) compiler
ii  mingw32-binutils                  2.20-0.2ubuntu1                          amd64        Minimalist GNU win32 (cross) binutils
ii  mingw32-runtime                   3.15.2-0ubuntu1                          all          Minimalist GNU win32 (cross) runtime
$ i586-mingw32msvc-gcc --version
i586-mingw32msvc-gcc (GCC) 4.2.1-sjlj (mingw32-2)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat VERSION 
1.6.0 (2014-12-22)
@aleks-f
Copy link
Member

aleks-f commented Jan 7, 2015

Network initialization is a Windows-specific thing and we have it done for the supported Visual Studio compiler. We don't officially support mingw, but we encourage contributions; so, you'll either have to come up with a solution or wait for one of the mingw contributors to help.

@asari-fd
Copy link
Contributor Author

asari-fd commented Jan 7, 2015

I understand. Thanks for your comment.

@Speakus
Copy link

Speakus commented Aug 20, 2016

The issue is inside Poco/Net/Net.h file. I update this to fix issue: http://pastebin.com/3fWrnw0q

@aleks-f aleks-f added the fixed label Jun 21, 2017
@aleks-f
Copy link
Member

aleks-f commented Jun 21, 2017

fixed

@aleks-f aleks-f closed this as completed Jun 21, 2017
@OldWolf2
Copy link

OldWolf2 commented Mar 6, 2018

With MinGW-w64 7.2.0 and poco-1.8.1-release, this problem recurs but only if POCO_STATIC=1 and we static link to Poco. (It worked correctly for a DLL-based POCO build). I work around this by explicitly calling Poco::Net::initializeNetwork() in my code.

@aleks-f
Copy link
Member

aleks-f commented Mar 6, 2018

@OldWolf2 See if this helps and let us know, we may add it:

diff --git a/Net/include/Poco/Net/Net.h b/Net/include/Poco/Net/Net.h
index 0d7bd35..f5bd912 100644
--- a/Net/include/Poco/Net/Net.h
+++ b/Net/include/Poco/Net/Net.h
@@ -92,7 +92,9 @@ void Net_API uninitializeNetwork();
 
 extern "C" const struct Net_API NetworkInitializer pocoNetworkInitializer;
 
-#if defined(Net_EXPORTS)
+#if defined(__GNUC__)
+       #define POCO_NET_FORCE_SYMBOL(x) void *__ ## x ## _fp =(void*)&x;
+#elif defined(Net_EXPORTS)
        #if defined(_WIN64) || defined(_WIN32_WCE)
                #define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
        #elif defined(_WIN32)

@aleks-f
Copy link
Member

aleks-f commented Mar 6, 2018

obviously
&& !defined(__GNUC__)
should be removed as well for the above to work

@jackorobot
Copy link
Contributor

@aleks-f The following patch I have tested and verified the following patch (building on your proposal) works with mingw gcc on windows. Will propose the change in a merge request if this is still something you would want to have implemented here.

diff --git a/Net/include/Poco/Net/Net.h b/Net/include/Poco/Net/Net.h
index 2e9735ab2..785de0ef0 100644
--- a/Net/include/Poco/Net/Net.h
+++ b/Net/include/Poco/Net/Net.h
@@ -93,11 +93,13 @@ std::string htmlize(const std::string& str);
 // Automate network initialization (only relevant on Windows).
 //

-#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_AUTOMATIC_LIB_INIT) && !defined(__GNUC__)
+#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_AUTOMATIC_LIB_INIT)

 extern "C" const struct Net_API NetworkInitializer pocoNetworkInitializer;

-#if defined(Net_EXPORTS)
+#if defined(__GNUC__)
+       #define POCO_NET_FORCE_SYMBOL(x) static void *__ ## x ## _fp = (void*)&x;
+#elif defined(Net_EXPORTS)
        #if defined(_WIN64) || (defined(_WIN32_WCE) && !defined(x86))
                #define POCO_NET_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
        #elif defined(_WIN32)

@aleks-f
Copy link
Member

aleks-f commented Jan 16, 2024

@jackorobot I don't mind it, you can send a pull. but it would be good to also have a CI job for that

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

No branches or pull requests

5 participants