Re: Cannot solve these linker errors, please help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: time.h functions: setting Cs concept of the time
    ... The interrupt servic routine counts the long integer representing the ANSI ... clock_t clock (void) ... Boolean_T parse_date(const char *str, unsigned *year, unsigned *month, ... unsigned int month,day,year; ...
    (comp.arch.embedded)
  • Cannot solve these linker errors, please help
    ... but for the first time I've to write ANSI C code using Visual Studio ... int main ...
    (microsoft.public.dotnet.languages.vc)
  • error LNK2019
    ... class Controller: public MessagesNotifier_Client ... void Controller::TempVerification(int a, int b) ... Im using Visual Studio .net 2003. ...
    (microsoft.public.dotnet.languages.vc)
  • forced use of void as function argument?
    ... I read that I have to use void as a function argument if it should be ... int somefunction{ ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Re: Create vj# dll
    ... Open Visual Studio. ... public class Class1 implements ITest ... public void set_Value(int number) ... Open Tools + Ole/COM Object Viewer in Visual Studio. ...
    (microsoft.public.dotnet.vjsharp)