By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,909 Members | 2,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,909 IT Pros & Developers. It's quick & easy.

Cannot solve these linker errors, please help

P: n/a
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
Oct 8 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Oltmans wrote:
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

--
Cholo Lennon
Bs.As.
ARG
Oct 8 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.