Thread overview
snn.lib , setmode and linker errors
Mar 21, 2007
Charlie
Mar 21, 2007
Charlie
Mar 21, 2007
Derek Parnell
Mar 21, 2007
Charlie
March 21, 2007
Hi,

Im trying to write a CGI lib in D, and it requires stdin be put in binaru mode for windows, which is done with setmode(), declared in io.h and is in snn.lib.  Here is the code:

import std.c.stdio;

void main ()
{

  version ( Windows )
    {
      int O_BINARY = 0x8000;
      extern ( C ) int setmode(int,int);
      setmode(stdin._file ,O_BINARY);
    }

}

And the error:

stest.obj(stest)
 Error 42: Symbol Undefined __D5stest4mainFZv7setmodeMUiiZi
--- errorlevel 1

Im explictly linking to snn.lib ( is that needed ? ) , why is it still undefined ?

Thanks,
Charlie
March 21, 2007
The following C code works fine ( taken from digitalmars website http://www.digitalmars.com/rtl/io.html#_setmode ) :

#include <stdio.h>
#include <io.h>
#include <fcntl.h>

void main ()
{
   int result;
   result = _setmode(_fileno(stdin), _O_BINARY);
   if (result == -1)
      perror("Error setting mode");
   else
      printf("Printer successfully set to text mode\n");
}




Charlie wrote:
> Hi,
> 
> Im trying to write a CGI lib in D, and it requires stdin be put in binaru mode for windows, which is done with setmode(), declared in io.h and is in snn.lib.  Here is the code:
> 
> import std.c.stdio;
> 
> void main ()
> {
> 
>   version ( Windows )
>     {
>       int O_BINARY = 0x8000;
>       extern ( C ) int setmode(int,int);
>       setmode(stdin._file ,O_BINARY);
>     }
> 
> }
> 
> And the error:
> 
> stest.obj(stest)
>  Error 42: Symbol Undefined __D5stest4mainFZv7setmodeMUiiZi
> --- errorlevel 1
> 
> Im explictly linking to snn.lib ( is that needed ? ) , why is it still undefined ?
> 
> Thanks,
> Charlie
March 21, 2007
On Tue, 20 Mar 2007 19:53:28 -0500, Charlie wrote:

> Hi,
> 
> Im trying to write a CGI lib in D, and it requires stdin be put in binaru mode for windows, which is done with setmode(), declared in io.h and is in snn.lib.  Here is the code:
> 
> import std.c.stdio;
> 
> void main ()
> {
> 
>    version ( Windows )
>      {
>        int O_BINARY = 0x8000;
>        extern ( C ) int setmode(int,int);
>        setmode(stdin._file ,O_BINARY);
>      }
> 
> }
> 
> And the error:
> 
> stest.obj(stest)
>   Error 42: Symbol Undefined __D5stest4mainFZv7setmodeMUiiZi
> --- errorlevel 1
> 
> Im explictly linking to snn.lib ( is that needed ? ) , why is it still undefined ?
> 
> Thanks,
> Charlie

Move the 'extern(C)' declaration out of the main() function.

 import std.c.stdio;
 version ( Windows ) extern ( C ) int setmode(int,int);

 void main ()
 {
   version ( Windows )
     {
       int O_BINARY = 0x8000;
       setmode(stdin._file ,O_BINARY);
     }
 }
-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
21/03/2007 12:10:30 PM
March 21, 2007
Many thanks!

Derek Parnell wrote:
> On Tue, 20 Mar 2007 19:53:28 -0500, Charlie wrote:
> 
>> Hi,
>>
>> Im trying to write a CGI lib in D, and it requires stdin be put in binaru mode for windows, which is done with setmode(), declared in io.h and is in snn.lib.  Here is the code:
>>
>> import std.c.stdio;
>>
>> void main ()
>> {
>>
>>    version ( Windows )
>>      {
>>        int O_BINARY = 0x8000;
>>        extern ( C ) int setmode(int,int);
>>        setmode(stdin._file ,O_BINARY);
>>      }
>>
>> }
>>
>> And the error:
>>
>> stest.obj(stest)
>>   Error 42: Symbol Undefined __D5stest4mainFZv7setmodeMUiiZi
>> --- errorlevel 1
>>
>> Im explictly linking to snn.lib ( is that needed ? ) , why is it still undefined ?
>>
>> Thanks,
>> Charlie
> 
> Move the 'extern(C)' declaration out of the main() function.
> 
>  import std.c.stdio;
>  version ( Windows ) extern ( C ) int setmode(int,int);
> 
>  void main ()
>  {
>    version ( Windows )
>      {
>        int O_BINARY = 0x8000;
>        setmode(stdin._file ,O_BINARY);
>      }
>  }