Discussion:
linking with /NODEFAULTLIB
(too old to reply)
AG
2012-01-20 10:12:11 UTC
Permalink
Hello,

I have the following short program:

/*------------------test.cpp-----------------------------------*/
int main(int argc, char * argv[])
{
if ( argv[1][0] == 'a' ) return 3;
else return 2;
}
/*-------------------------------------------------------------------
*/

which compiles fine with /NODEFAULTLIB /ENTRY:"main" +default Release
config set up.
test.exe b
echo %ErrorLevel%
2
test.exe a
echo %ErrorLevel%
2

If I compile the same program in default Debug config, the return
values of the program are ok (2 or 3 depending on the input).

Why my Release config with /NODEFAULTLIB /ENTRY:"main" does not work ?

I use Visual C++ Express 2010.

A.G.
Uwe Sieber
2012-01-23 05:27:39 UTC
Permalink
Because a 'main' is called by the C-Runtime which
did the commandline parsing and some other stuff.
The real entry function has no parameters, so
what you grab with argc and argv is kind of random.
Here is some backgroud and a tiny c-lib:
http://www.microsoft.com/msj/archive/S569.aspx

Uwe
Post by AG
Hello,
/*------------------test.cpp-----------------------------------*/
int main(int argc, char * argv[])
{
if ( argv[1][0] == 'a' ) return 3;
else return 2;
}
/*-------------------------------------------------------------------
*/
which compiles fine with /NODEFAULTLIB /ENTRY:"main" +default Release
config set up.
test.exe b
echo %ErrorLevel%
2
test.exe a
echo %ErrorLevel%
2
If I compile the same program in default Debug config, the return
values of the program are ok (2 or 3 depending on the input).
Why my Release config with /NODEFAULTLIB /ENTRY:"main" does not work ?
I use Visual C++ Express 2010.
A.G.
Loading...