Password program problem...

V

void_3e01

I've been trying to get a login program to work for quite some time now
but for some reason I get the same error. I have chosen a small peice
of code that only gives me One error


#include <unistd.h>
#include <stdlib.h>
#include <iostream>



char * getpass(const char *prompt);

using namespace std;
int main()
{
char *password = getpass("Password: ");
return 0;
}


and the error is:
[Linker error] undefined reference to `getpass(char const*)'

P.S. My compiler is Dev-cpp


-Thanks in advance;
 
A

Alan Johnson

I've been trying to get a login program to work for quite some time now
but for some reason I get the same error. I have chosen a small peice
of code that only gives me One error


#include <unistd.h>
#include <stdlib.h>
#include <iostream>



char * getpass(const char *prompt);

using namespace std;
int main()
{
char *password = getpass("Password: ");
return 0;
}


and the error is:
[Linker error] undefined reference to `getpass(char const*)'

P.S. My compiler is Dev-cpp


-Thanks in advance;


getpass isn't part of the C++ standard library. As far as I can tell,
it also is not part of any popular standard (POSIX, SUS3, etc). It
appears on my machine, but the first line of the man page is:
"This function is obsolete. Do not use it."
 
J

Jonathan Mcdougall

I've been trying to get a login program to work for quite some time now
but for some reason I get the same error. I have chosen a small peice
of code that only gives me One error

#include <unistd.h>
#include <stdlib.h>
#include <iostream>

char * getpass(const char *prompt);

Umm.. where's the definition for this function? That function should
have a body somewhere.
using namespace std;
int main()
{
char *password = getpass("Password: ");
return 0;
}


and the error is:
[Linker error] undefined reference to `getpass(char const*)'

P.S. My compiler is Dev-cpp

Dev-c++ is an IDE, not a compiler.


Jonathan
 
I

Ian Collins

I've been trying to get a login program to work for quite some time now
but for some reason I get the same error. I have chosen a small peice
of code that only gives me One error


#include <unistd.h>
#include <stdlib.h>
#include <iostream>



char * getpass(const char *prompt);
If you have to provide a prototype for a function that you think is in a
standard header (probably unistd.h in this case), then most likely the
function isn't in your platforms standard libraries.
 
S

Selwyn Alcantara

Well actually, it does contain constants and types needed for POSIX
compatibility but is deprecated and is not std.

Seeing as how it doesn't exist anymore (or shouldn't) you need to roll
your own. The compiler understands your declaration but can't find your
definition so it spits out that error. Your error happens whennever
there is a declaration but no definition.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top