I got a executable program from my former colleague who has left my company.
Its main function looks like this:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int nRetCode = 5;

SL_Begin_Process(__argc,__argv, NULL, "Customer_Test", "");

......
}

In this program, it uses C and Fortran code. When I compiled this program
in Debug mode, I got the following error:
Customer_Test.obj : error LNK2001: unresolved external symbol ___argc
Customer_Test.obj : error LNK2001: unresolved external symbol ___argv
Debug/Customer_Test.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

My question is why these errors occured? In a C program, argc and argv is
defined in the main function like
int main(int argc, char *argv[]){}. However, I can not find where __argc
and __argv are defined. If I compiled in Release mode, it compiles
successfully without such error.

Any of your help is greatly appreciated.

Tony

RE: compiling error in C++, Fortran, C -- newbie question by joncaves

joncaves
Thu Aug 14 12:40:20 CDT 2003

>From: "Tony Hu" <bytj@yahoo.com>
>Subject: compiling error in C++, Fortran, C -- newbie question
>Date: Thu, 14 Aug 2003 13:11:17 -0400
>Lines: 34
>
>I got a executable program from my former colleague who has left my
company.
>Its main function looks like this:
>
>int APIENTRY WinMain(HINSTANCE hInstance,
> HINSTANCE hPrevInstance,
> LPSTR lpCmdLine,
> int nCmdShow)
>{
> int nRetCode = 5;
>
> SL_Begin_Process(__argc,__argv, NULL, "Customer_Test", "");
>
>......
>}
>
>In this program, it uses C and Fortran code. When I compiled this program
>in Debug mode, I got the following error:
>Customer_Test.obj : error LNK2001: unresolved external symbol ___argc
>Customer_Test.obj : error LNK2001: unresolved external symbol ___argv
>Debug/Customer_Test.exe : fatal error LNK1120: 2 unresolved externals
>Error executing link.exe.
>
>My question is why these errors occured? In a C program, argc and argv is
>defined in the main function like
>int main(int argc, char *argv[]){}. However, I can not find where __argc
>and __argv are defined. If I compiled in Release mode, it compiles
>successfully without such error.
>
>Any of your help is greatly appreciated.
>
>Tony
>

I suspect that these variables must be defined in the program somewhere: as
the entry point
being used in the program is WinMain the cmd-line arguments are passed in
via lpCmdLine. It
seems to me that there should be somecode somwhere that takes lpCmdLine and
converts it into
a C-style arguments list using __argc and __argv.

Note: If these are user defined variables then they should not start with a
double '_' as such
variables are reserved for the implementation.

--
Jonathan Caves, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.


Re: compiling error in C++, Fortran, C -- newbie question by Igor

Igor
Thu Aug 14 12:53:03 CDT 2003

"Jonathan Caves [MSFT]" <joncaves@online.microsoft.com> wrote in message
news:FXZkisoYDHA.2000@cpmsftngxa06.phx.gbl...
> >From: "Tony Hu" <bytj@yahoo.com>
> >I got a executable program from my former colleague who has left my
> company.
> >Its main function looks like this:
> > SL_Begin_Process(__argc,__argv, NULL, "Customer_Test", "");
> >
> >Customer_Test.obj : error LNK2001: unresolved external symbol ___argc
> >Customer_Test.obj : error LNK2001: unresolved external symbol ___argv
> >Debug/Customer_Test.exe : fatal error LNK1120: 2 unresolved externals
> >Error executing link.exe.
>
> I suspect that these variables must be defined in the program
somewhere: as
> the entry point
> being used in the program is WinMain the cmd-line arguments are passed
in
> via lpCmdLine. It
> seems to me that there should be somecode somwhere that takes
lpCmdLine and
> converts it into
> a C-style arguments list using __argc and __argv.

"Someone somewhere" is supposed to be CRT startup code. __argc and
__argv are declared in <stdlib.h> and are intended precisely to give
Windows applications access to parsed command line arguments.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: compiling error in C++, Fortran, C -- newbie question by joncaves

joncaves
Thu Aug 14 13:50:59 CDT 2003

>From: "Igor Tandetnik" <itandetnik@mvps.org>
>References: <ubRuUcoYDHA.1280@tk2msftngp13.phx.gbl>
<FXZkisoYDHA.2000@cpmsftngxa06.phx.gbl>
>Subject: Re: compiling error in C++, Fortran, C -- newbie question
>Date: Thu, 14 Aug 2003 13:53:03 -0400
>Lines: 35
>
>"Jonathan Caves [MSFT]" <joncaves@online.microsoft.com> wrote in message
>news:FXZkisoYDHA.2000@cpmsftngxa06.phx.gbl...
>> >From: "Tony Hu" <bytj@yahoo.com>
>> >I got a executable program from my former colleague who has left my
>> company.
>> >Its main function looks like this:
>> > SL_Begin_Process(__argc,__argv, NULL, "Customer_Test", "");
>> >
>> >Customer_Test.obj : error LNK2001: unresolved external symbol ___argc
>> >Customer_Test.obj : error LNK2001: unresolved external symbol ___argv
>> >Debug/Customer_Test.exe : fatal error LNK1120: 2 unresolved externals
>> >Error executing link.exe.
>>
>> I suspect that these variables must be defined in the program
>somewhere: as
>> the entry point
>> being used in the program is WinMain the cmd-line arguments are passed
>in
>> via lpCmdLine. It
>> seems to me that there should be somecode somwhere that takes
>lpCmdLine and
>> converts it into
>> a C-style arguments list using __argc and __argv.
>
>"Someone somewhere" is supposed to be CRT startup code. __argc and
>__argv are declared in <stdlib.h> and are intended precisely to give
>Windows applications access to parsed command line arguments.
>--
>With best wishes,
> Igor Tandetnik
>
>"For every complex problem, there is a solution that is simple, neat,
>and wrong." H.L. Mencken
>

I live and learn ... I never knew we did this. Thanks for Igor!

--
Jonathan Caves, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.