I am porting a WIN32 library on Linux. I am able to compile my library with no error. But when i try to link, it gives following linking error
undefined reference to `setmode'
I know that setmode function is standard library function and it resides in unistd.h and i provide the argument -lc while linking through terminal.
This is the link which lightened more about setmode.
Is there any help for the same?
I'm afraid these answers are nonsense. A program coming from the Win32 environment is using one of two possible setmode functions: either the Microsoft _setmode function documented in MSDN, or the Cygwin imitation of it called setmode.
This has nothing to do with the BSD setmode. It's a two-argument function which sets a file descriptor to either binary or text translation mode.
If your program expects this function, but you link to LibBSD, the program might link, but it is not correct.
The GNU C library doesn't provide an interface for manipulating the text or binary mode of FILE * streams or descriptors, and if it did, it wouldn't do anything, since the two modes are identical.
Code that needs the Cygwin setmode function on Cygwin can probably just get away with not doing anything on Unix: so that is to say:
#ifdef __CYGWIN__
setmode(fileno(my_stdio_stream), O_BINARY);
#elif _WIN32
_setmode(_fileno(my_stdio_stream), _O_BINARY);
#else
/* nothing on systems with no text-vs-binary mode */
#endif
I had trouble with this one too; the linking happens during the make process, so this will occur and people who have no business dealing with c (like me) try to use cygwin or mingw. Thanks to Cairnarvon's answer, I learned that a necessary include statement was missing:
#include <io.h>
...in modules which call the setmode function (in my case, I am trying to build GDAL on Cygwin 64 bit). The error remained, until I saw these folks' answer and learned that the 64 bit version of Cygwin does not prepend underscores the way that the 32 bit version does. So I did the prepending manually and the make finished [more] successfully. I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With