Cannot solve these linker errors, please help

O

Oltmans

Hi all,

I've been writing C# code using Visual Studio 2005 for some time now
but for the first time I've to write ANSI C code using Visual Studio
2005. I followed this article http://support.microsoft.com/kb/829488
that does a good job of explaining how to write ANSI C using Visual
Studio 2005.
When I write the following program it compiles and runs fine. I get
the "Hello World" message shown in the command prompt.
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Hello World\n");


return 0;
}

However, when I run the following program I get two errors
#include <stdio.h>
#include <conio.h>


int main()
{
printf("Hello World\n");

display();

return 0;
}

void dislpay(){
printf("Hi, this is display()");
}


Here are the errors

1- Error 2 error LNK2019: unresolved external symbol _display
referenced in function _main Test.obj

2- Error 3 fatal error LNK1120: 1 unresolved externals C:\Documents
and Settings\Otlmans\My Documents\Visual Studio 2005\Projects\C
\FirstApplication\Debug\FirstApplication.exe

I've searched Internet and read various forum posts from people who
experienced similar error but I'm unable to resolve above two errors.
I'm new to ANSI C so any help will be highly appreciated. Thanks in
advance.

Thanks,
Oltmans
 
C

Cholo Lennon

Oltmans said:
Hi all,

I've been writing C# code using Visual Studio 2005 for some time now
but for the first time I've to write ANSI C code using Visual Studio
2005. I followed this article http://support.microsoft.com/kb/829488
that does a good job of explaining how to write ANSI C using Visual
Studio 2005.
When I write the following program it compiles and runs fine. I get
the "Hello World" message shown in the command prompt.
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Hello World\n");


return 0;
}

However, when I run the following program I get two errors
#include <stdio.h>
#include <conio.h>


int main()
{
printf("Hello World\n");

display();

return 0;
}

void dislpay(){
printf("Hi, this is display()");
}


Here are the errors

1- Error 2 error LNK2019: unresolved external symbol _display
referenced in function _main Test.obj

2- Error 3 fatal error LNK1120: 1 unresolved externals C:\Documents
and Settings\Otlmans\My Documents\Visual Studio 2005\Projects\C
\FirstApplication\Debug\FirstApplication.exe

I've searched Internet and read various forum posts from people who
experienced similar error but I'm unable to resolve above two errors.
I'm new to ANSI C so any help will be highly appreciated. Thanks in
advance.

Thanks,
Oltmans

1-I will ignore the typo in the display name ("dislpay")
2-In C language you must define a symbol before use it. Move the function
before main or use a prototype:

void display(){
printf("Hi, this is display()");
}

int main()
{
printf("Hello World\n");
display();
return 0;
}

Or

/* prototype */
void display();

int main()
{
printf("Hello World\n");
display();
return 0;
}

void display(){
printf("Hi, this is display()");
}


Regards
 

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

Top