Is it (or would it) be possible to use glibc under windows (as a replacement of msvcrt)? I know this is a stupid question, and answers like cygwin will pop up, but I am really asking: is it possible to link to glibc on windows and use all library functions like with msvcrt?
Asked
Active
Viewed 1.4k times
2 Answers
6
glibc used to work on different *nixes once , these days glibc is quite Linux specific. It will certainly not work on windows.

nos
- 223,662
- 58
- 417
- 506
-
And thus we should rewrite our open-sourced code on each platform and surround it by lot of preprocessor's #ifdefs... Cross-platform with two different worlds is myth: Windows on one side and Linux, BSD, OS X, iOS etc. (them all cross-platform, besides!) - on another side. It is war of OSes which results in lot of poor-quality code... – Brian Cannard Jul 09 '14 at 23:31
-
@BrianHaak your claims have little to do with glibc. Glibc is just one of many libs *(granted though, one of most popular)* implementing standard c functions *(and a bit of other churn)*. As far as you're using standard c functions, you don't need platform-dependent #ifdefs. Your example from the other comment here is using an extension of GCC, and notably α) have nothing to do with libraries, and β) such a code is generally frowned upon, unless author have really compelling reasons. – Hi-Angel Jul 07 '17 at 20:56
2
A possible workaround could exist: if someone combines http://0xef.wordpress.com/2012/11/17/emulate-linux-system-calls-on-windows/ with http://www.musl-libc.org/ and compiles source code with gcc against musl libc instead of glibc. So, I can't understand why nobody writes a such glibc analog for Windows. :-(

Brian Cannard
- 852
- 9
- 20
-
Thanks for the interesting reference. It seems like quite a hack to rely on handling the exceptions, but hey, it might just work well enough... Pretty neat nonetheles! – rubenvb Jul 10 '14 at 06:58
-
Actually, I need to cross-compile open source libraries which developed for Linux only. They use no system references but modern GCC's C and C++ and its STANDARD library calls - something that implemented by GLibC/musl-libc/newlib. I have disappointed in Visual Studio C compiler. I would like to compile code with GCC on Linux/OS X then move OBJECT FILES to Windows and link them with Windows-platform specific application code, which compiled with MSVC. So, THE ONLY PROBLEM I HAVE - on Windows, there is NO GCC-compatible STANDARD C LIBRARY!!! – Brian Cannard Jul 10 '14 at 08:16
-
Otherwise, how to compile this on Windows: `typedef uint8_t v16 __attribute__ ((vector_size (16)));` and so on, [QFS Reed-Solomon fragment on GitHub](https://github.com/quantcast/qfs/blob/master/src/cc/qcrs/prim.h) ? – Brian Cannard Jul 10 '14 at 08:21
-
You do know about [MinGW-w64](mingw-w64.sourceforge.net), don't you? It provides a standard C99 library, built around and on top of msvcrt.dll. You can in principle link 32-bit C code built with this GCC with MSVC. – rubenvb Jul 10 '14 at 08:32
-
Really? It was first solution I've tried :-) I don't like how GCC compiles C code on Windows. But, hey, it has standard C library atop msvcrt.dll? - could I compile its C library in Linux GCC then import object file to build it with MSVC' make.exe? – Brian Cannard Jul 10 '14 at 08:45
-
why do you insist on building a single object file? What is preventing you from building two object files anyway? And what is there not to "like" about GCC's C code on Windows? – rubenvb Jul 10 '14 at 08:55
-
Ah, maybe cross-compiling a common code dll in MinGW on Linux would be best idea.. Performance tests on Internet shows native Linux GCC faster results than MinGW compiled on Windows. – Brian Cannard Jul 10 '14 at 09:00
-
2"Performance tests on the Internet"... Yeah, that's great. Test yourself. And don't compare apples to oranges: comparing binary code execution cross-OS is near to pointless: better would be to compare MSVC vs MinGW-w64 GCC, and I bet you MinGW-w64 GCC is quite fast `;-)` – rubenvb Jul 10 '14 at 09:36
-
Just such a kind of test I need! But my sources of interest are not compiled in MSVC))) So, I need to decide: branch open source files, rewrite them to support MSVC (and integrate into them all that funny cakes added by a lot of devs worldwide REGULARLY - such pain!). Or just compile a dll - in Linux, yes? Also, I don't understand - is any difference in code performance between 3 cases: MinGW-w64 on Windows, same with cross-compile on Linux, and native GCC on Linux? Why nobody have published such tests? – Brian Cannard Jul 10 '14 at 09:46
-
1Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/57082/discussion-between-rubenvb-and-avesus). – rubenvb Jul 10 '14 at 10:09
-
To make things clear: I think about compiling a kind of code blob which is compatible with Android x86, Windows and Mac OS, and Linux, BSD - it is just enough to build only 2 blobs: x86 and AMD64. Point. :-) Ofcourse, another blobs are for ARM. I wander if it is possible to write my own cross-platform code in such manner wich supports the mentioned blobs. By the way, I going to license my code with GPL only, so blobs are not problem: actually, I think that dynamic-linking GPL-bypass trick is the stupid deception of ourselves before lawsuits and money contingencies))) – Brian Cannard Jul 11 '14 at 00:49
-
By the way, today we have WebAssembly, which is extremely interesting... – Brian Cannard May 18 '18 at 18:44