From: Alexander F. <ale...@gm...> - 2007-02-27 10:40:34
|
Hello MinGW-users, I'm working on a small network daemon (which I hope to release under BSD license soon) and it compiles and runs fine on OpenBSD, Linux and Cygwin. It binds to a TCP-port (1935 by default), then accept()s clients there and readv()s/writev()s data between them. Now I'm trying to compile it under MinGW, because I hope to get a binary which other users would be able to download and run on their Windows PCs without having to install Cygwin or MinGW. (Is that possible at all or have I misunderstood MinGW's purpose?) My current problem is that I can't locate the headers: /h/src/rtmpd> /usr/local/bin/gcc -v Reading specs from C:/msys/1.0/local/bin/../lib/gcc/mingw32/3.4.2/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.2 (mingw-special) /h/src/rtmpd> make CC=/usr/local/bin/gcc /usr/local/bin/gcc -Wall -DNDEBUG -I openbsd-compat -c src/rtmpd.c -o build/rtmpd.o In file included from src/rtmpd.c:19: src/rtmpd.h:22:18: poll.h: No such file or directory src/rtmpd.h:23:19: stdio.h: No such file or directory src/rtmpd.h:24:20: signal.h: No such file or directory src/rtmpd.h:25:20: stdlib.h: No such file or directory src/rtmpd.h:26:19: errno.h: No such file or directory src/rtmpd.h:28:26: sys/resource.h: No such file or directory src/rtmpd.h:29:19: ctype.h: No such file or directory src/rtmpd.h:30:20: syslog.h: No such file or directory src/rtmpd.h:32:20: string.h: No such file or directory src/rtmpd.h:34:20: stdint.h: No such file or directory src/rtmpd.h:35:20: unistd.h: No such file or directory src/rtmpd.h:36:19: fcntl.h: No such file or directory src/rtmpd.h:37:24: sys/socket.h: No such file or directory src/rtmpd.h:38:24: netinet/in.h: No such file or directory src/rtmpd.h:39:20: assert.h: No such file or directory src/rtmpd.h:40:23: sys/param.h: No such file or directory src/rtmpd.h:41:23: sys/types.h: No such file or directory src/rtmpd.h:42:21: sys/uio.h: No such file or directory src/rtmpd.h:43:22: sys/stat.h: No such file or directory src/rtmpd.h:44:17: pwd.h: No such file or directory ...... Here is how I installed MinGW current on my Win XP Pro PC: - Run MSYS-1.0.10.exe - Opened MSYS bash-shell and extracted mingw-runtime-3.9.tar.gz and mingw-utils-0.3.tar.gz under /mingw - Extracted gcc-core-3.4.2-20040916-1.tar.gz and binutils-2.15.91-20040904-1.tar.gz under /usr/local - Additionally I've tried extracting w32api-3.6.tar.gz under /usr Do you have any suggestions please? Did I miss anything? I did read the INSTALL-docs and browsed the mailing list archive. Regards Alex PS: I also can't compile a hello world program, I'm probably missing something obvious, sorry: ~> uname -a MINGW32_NT-5.1 4DED01570 1.0.10(0.46/3/2) 2004-03-15 07:17 i686 unknown ~> cat hello.c #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world"); exit 1; } ~> /usr/local/bin/gcc -o hello hello.c hello.c:1:19: stdio.h: No such file or directory hello.c:2:20: stdlib.h: No such file or directory hello.c: In function `main': hello.c:6: error: `exit' undeclared (first use in this function) hello.c:6: error: (Each undeclared identifier is reported only once hello.c:6: error: for each function it appears in.) hello.c:6: error: syntax error before numeric constant ~> -- http://preferans.de |
From: Tor L. <tm...@ik...> - 2007-02-27 11:27:05
|
Alexander Farber writes: > My current problem is that I can't locate the headers: You also haven't ported your software to Windows. > src/rtmpd.h:22:18: poll.h: No such file or directory There is no poll() in Windows, thus no <poll.h> either. > src/rtmpd.h:23:19: stdio.h: No such file or directory This is odd. Can you compile a simple source file that does nothing except includes <stdio.h>? > src/rtmpd.h:24:20: signal.h: No such file or directory > src/rtmpd.h:25:20: stdlib.h: No such file or directory > src/rtmpd.h:26:19: errno.h: No such file or directory > src/rtmpd.h:29:19: ctype.h: No such file or directory > src/rtmpd.h:34:20: stdint.h: No such file or directory > src/rtmpd.h:35:20: unistd.h: No such file or directory > src/rtmpd.h:39:20: assert.h: No such file or directory > src/rtmpd.h:41:23: sys/types.h: No such file or directory > src/rtmpd.h:43:22: sys/stat.h: No such file or directory > src/rtmpd.h:40:23: sys/param.h: No such file or directory Those headers do exist in mingw. Once you find out why <stdio.h> isn't found, these will be found, too. > src/rtmpd.h:28:26: sys/resource.h: No such file or directory There is no getrusage() etc in Windows. > src/rtmpd.h:30:20: syslog.h: No such file or directory There is no syslog() in Windows. > src/rtmpd.h:36:19: fcntl.h: No such file or directory <fcntl.h> does exist, but there is no fcntl() as such. <fcntl.h> just defines the O_* bits you can pass to open(). > src/rtmpd.h:37:24: sys/socket.h: No such file or directory > src/rtmpd.h:38:24: netinet/in.h: No such file or directory > src/rtmpd.h:42:21: sys/uio.h: No such file or directory Google for hints how to port socket software to WinSock. The API is very similar to the normal Unix berkeley socket API, but uses different headers, and a couple of slightly different function names. Also, one important difference is that WinSock functions handle *only* sockets. It knows *nothing* about "file descriptors" (such as returned by open()) that the C library handles, and vice versa. I.e. you can't select() a file descriptor, or read() from a socket. > src/rtmpd.h:44:17: pwd.h: No such file or directory No getpw*() functions in Windows. > - extracted mingw-runtime-3.9.tar.gz and mingw-utils-0.3.tar.gz under /mingw > - Extracted gcc-core-3.4.2-20040916-1.tar.gz and > binutils-2.15.91-20040904-1.tar.gz under /usr/local > - Additionally I've tried extracting w32api-3.6.tar.gz under /usr You probably should have extracted all this in the same place, /mingw in your case. (Or /opt/mingw or /usr/local if you want something more Unixish.) I think this explains why <stdio.h> etc isn't found. As for porting your software to Windows, this can be lot of work if you haven't taken portability points of view into consideration at all when writing it. If you have intended the software to be portable to Windows from the start, you should have built it on Windows, too, every now and then to catch nonportable stuff early. Would have saved you lots of troble now. --tml |
From: Keith M. <kei...@to...> - 2007-02-27 11:36:58
|
Alexander Farber wrote: > Here is how I installed MinGW current on my Win XP Pro PC: > > - Run MSYS-1.0.10.exe > - Opened MSYS bash-shell and extracted mingw-runtime-3.9.tar.gz > and mingw-utils-0.3.tar.gz under /mingw > - Extracted gcc-core-3.4.2-20040916-1.tar.gz and > binutils-2.15.91-20040904-1.tar.gz under /usr/local > - Additionally I've tried extracting w32api-3.6.tar.gz under /usr > > Do you have any suggestions please? Did I miss anything? Yes; you have *not* installed MinGW correctly. You must install *all* of the MinGW components into the *same* prefix; i.e. *all* of: mingw-runtime-3.9 mingw-utils-0.3 gcc-core-3.4.2 binutils-2.15.91 w32api-3.6 *must* be installed to the *same* prefix; /mingw is the recommended default, but /usr/local should also work, provided /usr/local/bin is in your PATH. With MSYS-1.0.10, you must *not* put any of these in /usr. BTW, binutils-2.15.91 is *not* the current release; that would be binutils-2.16.91, distributed here: http://downloads.sourceforge.net/mingw/binutils-2.16.91-20060119-1.tar.gz I'd also suggest that the GCC and binutils releases here: https://sourceforge.net/project/showfiles.php?group_id=2435&package_id=82723&release_id=237094 https://sourceforge.net/project/showfiles.php?group_id=2435&package_id=82723&release_id=177460 and which are currently designated as `candidate' are sufficiently stable for production use; I think it's time we promoted them to `current'. Any objections? > I did read the INSTALL-docs and browsed the mailing list archive. Apparently not diligently enough: http://www.mingw.org/MinGWiki/index.php/GettingStarted HTH, Keith. |
From: Alexander F. <ale...@gm...> - 2007-02-27 12:58:08
|
Hello Keith, On 2/27/07, Keith MARSHALL <kei...@to...> wrote: > Alexander Farber wrote: > Yes; you have *not* installed MinGW correctly. You must install > *all* of the MinGW components into the *same* prefix; i.e. *all* of: ... > http://www.mingw.org/MinGWiki/index.php/GettingStarted oh yes, sorry - I had missed the Wiki. I have reinstalled it (with the newer gcc and binutils) as you've recommended (everything under /mingw) and now a simple hello-world program compiles and works (even on other PCs): ~> gcc -v Reading specs from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.5/specs Configured with: ../gcc-3.4.5/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.5 (mingw special) But a small program which I'd like to bind to a TCP socket doesn't link: ~> cat bind.c #include <stdio.h> #include <winsock.h> int main(int argc, char *argv[]) { int fd; struct sockaddr_in addr; if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) perror("Can't create listening socket"); bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(1935); if (bind(fd, (struct sockaddr *) &addr, sizeof(addr))) perror("Can't bind listening socket"); if (listen(fd, SOMAXCONN)) perror("Can't listen on socket"); fprintf(stderr, "Ok, listening on socket %d\n", fd); exit(10); } ~> gcc -o bind bind.c C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0x42): undefined reference to `socket@12' C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0x6f): undefined reference to `bzero' C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0x81): undefined reference to `htonl@4' C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0x93): undefined reference to `htons@4' C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0xb4): undefined reference to `bind@12' C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0xda): undefined reference to `listen@8' collect2: ld returned 1 exit status I've found an AF_INET in the winsock.h - that's why I've included it above ~> grep -rw AF_INET /mingw/include /mingw/include/winsock.h:#define AF_INET 2 /mingw/include/winsock.h:#define PF_INET AF_INET /mingw/include/winsock2.h:#define AF_INET 2 /mingw/include/winsock2.h:#define PF_INET AF_INET The "socket" is in the same header, but my program fails to link. Any hints on how to fix it? I've got Tor's comment, that I'd need to move from poll() to select()... The pwd() I only needed because I'm dropping privilleges - I can #ifdef it out... Regards Alex -- http://preferans.de |
From: Tor L. <tm...@ik...> - 2007-02-27 13:15:23
|
Alexander Farber writes: > C:/DOCUME~1/afarber/LOCALS~1/Temp/ccsVbaaa.o:bind.c:(.text+0x42): > undefined reference to `socket@12' Link with -lwsock32. (Or preferrably, include <winsock2.h> and link with -lws2_32, although both ways should work as well as far as I know.) If you read some WinSock tutorial you will also learn that you need to initialise it by calling WSAStartup() before calling any WinSock functions. --tml |
From: Michael G. <mg...@te...> - 2007-02-27 13:16:11
|
> But a small program which I'd like to bind to a TCP socket doesn't link: >=20 > ~> cat bind.c > #include <stdio.h> > #include <winsock.h> >=20 > int > main(int argc, char *argv[]) > { > int fd; > struct sockaddr_in addr; >=20 > if ((fd =3D socket(AF_INET, SOCK_STREAM, 0)) =3D=3D -1) > perror("Can't create listening socket"); >=20 > bzero(&addr, sizeof(addr)); > addr.sin_family =3D AF_INET; > addr.sin_addr.s_addr =3D htonl(INADDR_ANY); > addr.sin_port =3D htons(1935); >=20 > if (bind(fd, (struct sockaddr *) &addr, sizeof(addr))) > perror("Can't bind listening socket"); > if (listen(fd, SOMAXCONN)) > perror("Can't listen on socket"); >=20 > fprintf(stderr, "Ok, listening on socket %d\n", fd); > exit(10); > } You are not using Winsock correctly. First of all you don't issue a WSAStartup(). You still have not checked the Wiki diligently enough: http://www.mingw.org/MinGWiki/index.php/sockets HTH, Michael =2D-=20 Technosis GmbH, Gesch=E4ftsf=FChrer: Michael Gerdau, Tobias Dittmar Sitz Hamburg; HRB 89145 Amtsgericht Hamburg Vote against SPAM - see http://www.politik-digital.de/spam/ Michael Gerdau email: mg...@te... GPG-keys available on request or at public keyserver |
From: Brian D. <br...@de...> - 2007-02-27 13:19:44
|
Alexander Farber wrote: > But a small program which I'd like to bind to a TCP socket doesn't link: > > ~> cat bind.c > #include <stdio.h> > #include <winsock.h> > > int > main(int argc, char *argv[]) > { > int fd; > struct sockaddr_in addr; > > if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) > perror("Can't create listening socket"); Error: You did not call WSAStartup(). This must be done before using any socket functions. Please read up on Winsock: <http://msdn2.microsoft.com/en-us/library/ms740673.aspx>. > bzero(&addr, sizeof(addr)); Error: bzero() does not exist in MSVCRT. > ~> gcc -o bind bind.c Error: You did not link against the winsock library. Add -lws2_32 to the end of the command line. > I've found an AF_INET in the winsock.h - > that's why I've included it above Stop guessing and read MSDN. Everything you need to know about which headers to include and which libraries to link with is documented for every function. When MSDN says "link against foo.lib", that means specify -lfoo to gcc. http://msdn2.microsoft.com/en-us/library/ms738545.aspx Brian |
From: Alexander F. <ale...@gm...> - 2007-02-27 13:30:03
|
Hi all, On 2/27/07, Brian Dessent <br...@de...> wrote: > Stop guessing and read MSDN. Everything you need to know about which > headers to include and which libraries to link with is documented for > every function. When MSDN says "link against foo.lib", that means > specify -lfoo to gcc. > > http://msdn2.microsoft.com/en-us/library/ms738545.aspx uh ok, I don't want to learn Windows sockets. I think I'll give up on MinGW. I was expecting it to be similar to Cygwin (where my Unix-program compiles very easily), but without the need to install anything for the end users. Looks like it is smth. different (not necessarily bad, but it isn't suiting my needs) Thanks Alex -- http://preferans.de |
From: Keith M. <kei...@to...> - 2007-02-27 13:43:58
|
Alexander Farber wrote: > uh ok, I don't want to learn Windows sockets. > I think I'll give up on MinGW. Ok, then that leaves you with... > I was expecting it to be similar to Cygwin (where my > Unix-program compiles very easily), but without the > need to install anything for the end users. ...which means you must distribute cygwin1.dll along with your application; be sure to read, understand and comply with its licensing requirements. > Looks like it is smth. different (not necessarily bad, > but it isn't suiting my needs) Windows is a very different platform from *nix. If you want to support it *natively*, then you simply cannot avoid learning at least some of its peculiarities. MinGW gives you an excellent tool for the job, but it isn't a `magic bullet', which obviates the need for learning something about the platform differences. Regards, Keith. |
From: Alexander F. <ale...@gm...> - 2007-02-27 14:18:49
|
Thank you all for the very useful comments. Maybe I'll try it again in 1-2 months Regards Alex -- http://preferans.de |
From: Brian D. <br...@de...> - 2007-02-27 13:39:42
|
Alexander Farber wrote: > uh ok, I don't want to learn Windows sockets. > I think I'll give up on MinGW. > > I was expecting it to be similar to Cygwin (where my > Unix-program compiles very easily), but without the > need to install anything for the end users. If you want an app that doesn't require anything extra then you have to use the native Win32 APIs and the Microsoft C runtime library (MSVCRT); this means Winsock. It's an either-or: either you have an emulation library like Cygwin or you use the native API. And using the native API is what MinGW is about, hence the "minimalist" in its name. I wouldn't give up so fast. The Winsock library is one of the easiest to port, since it is very close to the unix socket model. If all you have to do is socket networking, then it should be very easy. Brian |