problems with compiling printlog function

Archive of the old Parsimony forum. Some messages couldn't be restored. Limitations: Search for authors does not work, Parsimony specific formats do not work, threaded view does not work properly. Posting is disabled.

problems with compiling printlog function

Postby Uri Blass » 27 Feb 2004, 18:17

Geschrieben von: / Posted by: Uri Blass at 27 February 2004 18:17:54:

I copied the function from
http://f11.parsimony.net/forum16635/messages/61760.htm
I tried to compile it with no success.
I get one warning and 4 errors inspite of starting with 2 includes
Here is the code(defs.h and data.h are files that I include in every file of my program and they include the global varaibles of the program.
#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && fpLog != (FILE *)NULL)
{
vfprintf(fpLog, szFormat, vargs);
fflush(fpLog);
}
va_end(vargs);
}
the warning is
warning C4096: '__cdecl' must be used with '...'
The errors are that g_bLogging and fpLog are not defined.
I guess that the error means that I need to have global varaible for integer and to use logmovei that is defined as external FILE* in data.h and as FILE* in data.c instead of using fpLog but I first care about the first warning.
I tried to define it both as .c and as .cpp
Here are the failure to compile with .c
Compiling...
logfunctions.c
C:\unzipped\movei257source\logfunctions.c(7) : warning C4096: '__cdecl' must be used with '...'
C:\unzipped\movei257source\logfunctions.c(13) : error C2065: 'g_bLogging' : undeclared identifier
C:\unzipped\movei257source\logfunctions.c(13) : error C2065: 'fpLog' : undeclared identifier
C:\unzipped\movei257source\logfunctions.c(13) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'struct _iobuf *'
C:\unzipped\movei257source\logfunctions.c(15) : warning C4047: 'function' : 'struct _iobuf *' differs in levels of indirection from 'int '
C:\unzipped\movei257source\logfunctions.c(15) : warning C4024: 'vfprintf' : different types for formal and actual parameter 1
C:\unzipped\movei257source\logfunctions.c(16) : warning C4047: 'function' : 'struct _iobuf *' differs in levels of indirection from 'int '
C:\unzipped\movei257source\logfunctions.c(16) : warning C4024: 'fflush' : different types for formal and actual parameter 1
Error executing cl.exe.
logfunctions.obj - 2 error(s), 6 warning(s)
With .cpp I get more errors and less warnings and it seems that part of the warning turn out to be errors when part of them disappear
Compiling...
logfunctions.cpp
C:\unzipped\movei257source\logfunctions.cpp(7) : warning C4096: '__cdecl' must be used with '...'
C:\unzipped\movei257source\logfunctions.cpp(13) : error C2065: 'g_bLogging' : undeclared identifier
C:\unzipped\movei257source\logfunctions.cpp(13) : error C2065: 'fpLog' : undeclared identifier
C:\unzipped\movei257source\logfunctions.cpp(13) : error C2446: '!=' : no conversion from 'struct _iobuf *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\unzipped\movei257source\logfunctions.cpp(13) : error C2040: '!=' : 'int' differs in levels of indirection from 'struct _iobuf *'
Error executing cl.exe.
logfunctions.obj - 4 error(s), 1 warning(s)
Uri
Uri Blass
 

Re: problems with compiling printlog function

Postby Tom Likens » 27 Feb 2004, 19:00

Geschrieben von: / Posted by: Tom Likens at 27 February 2004 19:00:55:
Als Antwort auf: / In reply to: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 18:17:54:

Hey Uri,
Some answers interspersed below.
I copied the function from
http://f11.parsimony.net/forum16635/messages/61760.htm
I tried to compile it with no success.
I get one warning and 4 errors inspite of starting with 2 includes
Here is the code(defs.h and data.h are files that I include in every
file of my program and they include the global varaibles of the program.

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && fpLog != (FILE *)NULL)
{
vfprintf(fpLog, szFormat, vargs);
fflush(fpLog);
}
va_end(vargs);
}
the warning is
warning C4096: '__cdecl' must be used with '...'
The errors are that g_bLogging and fpLog are not defined.
I guess that the error means that I need to have global varaible for
integer and to use logmovei that is defined as external FILE* in data.h
and as FILE* in data.c instead of using fpLog but I first care about the
first warning.
If you are using the "fastcall" linking option under Windows it will cause
the error you're seeing. Changing the function prototype (and the actual
function) to:
void __cdecl PrintLog(const char *szFormat, ...);
void __cdecl PrintLog(const char *szFormat, ...)
{
etc.
}
should fix things (I should have mentioned this initially). I have this
set up as a define that so that when I compile the program under Linux the
__cdecl is removed by the preprocessor.
As you surmised, you need two global variable to make this work in the
form presented. I think once you get the compiler to recognize the two
globals the remaining errors will likely go away, (if not feel free to
post the *new* errors here ;)
regards,
--tom
Tom Likens
 

Re: problems with compiling printlog function

Postby Matthias Gemuh » 27 Feb 2004, 19:24

Geschrieben von: / Posted by: Matthias Gemuh at 27 February 2004 19:24:37:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Tom Likens at 27 February 2004 19:00:55:




// printing both to the logfile and to stdout or nul
void PrintLog(FILE *fp, bool bLogging, char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat); vprintf(szFormat, vargs); fflush(stdout);
if (bLogging && fp != (FILE *)NULL) { vfprintf(fp, szFormat, vargs); fflush(fp); }
va_end(vargs);
}

I don't use fastcall, so I don't need __cdecl.
Would fastcall "fasten" my program by 10% or more ?

/Matthias.


BigLion + Taktix
Matthias Gemuh
 

Re: problems with compiling printlog function

Postby Uri Blass » 27 Feb 2004, 19:55

Geschrieben von: / Posted by: Uri Blass at 27 February 2004 19:55:56:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Tom Likens at 27 February 2004 19:00:55:
Hey Uri,
Some answers interspersed below.
I copied the function from
http://f11.parsimony.net/forum16635/messages/61760.htm
I tried to compile it with no success.
I get one warning and 4 errors inspite of starting with 2 includes
Here is the code(defs.h and data.h are files that I include in every
file of my program and they include the global varaibles of the program.

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && fpLog != (FILE *)NULL)
{
vfprintf(fpLog, szFormat, vargs);
fflush(fpLog);
}
va_end(vargs);
}
the warning is
warning C4096: '__cdecl' must be used with '...'
The errors are that g_bLogging and fpLog are not defined.
I guess that the error means that I need to have global varaible for
integer and to use logmovei that is defined as external FILE* in data.h
and as FILE* in data.c instead of using fpLog but I first care about the
first warning.
If you are using the "fastcall" linking option under Windows it will cause
the error you're seeing. Changing the function prototype (and the actual
function) to:
void __cdecl PrintLog(const char *szFormat, ...);
void __cdecl PrintLog(const char *szFormat, ...)
{
etc.
}
should fix things (I should have mentioned this initially). I have this
set up as a define that so that when I compile the program under Linux the
__cdecl is removed by the preprocessor.
As you surmised, you need two global variable to make this work in the
form presented. I think once you get the compiler to recognize the two
globals the remaining errors will likely go away, (if not feel free to
post the *new* errors here ;)
regards,
--tom
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol "struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol "int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Uri Blass
 

Re: problems with compiling printlog function

Postby Uri Blass » 27 Feb 2004, 19:59

Geschrieben von: / Posted by: Uri Blass at 27 February 2004 19:59:38:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 19:55:56:
Hey Uri,
Some answers interspersed below.
I copied the function from
http://f11.parsimony.net/forum16635/messages/61760.htm
I tried to compile it with no success.
I get one warning and 4 errors inspite of starting with 2 includes
Here is the code(defs.h and data.h are files that I include in every
file of my program and they include the global varaibles of the program.

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && fpLog != (FILE *)NULL)
{
vfprintf(fpLog, szFormat, vargs);
fflush(fpLog);
}
va_end(vargs);
}
the warning is
warning C4096: '__cdecl' must be used with '...'
The errors are that g_bLogging and fpLog are not defined.
I guess that the error means that I need to have global varaible for
integer and to use logmovei that is defined as external FILE* in data.h
and as FILE* in data.c instead of using fpLog but I first care about the
first warning.
If you are using the "fastcall" linking option under Windows it will cause
the error you're seeing. Changing the function prototype (and the actual
function) to:
void __cdecl PrintLog(const char *szFormat, ...);
void __cdecl PrintLog(const char *szFormat, ...)
{
etc.
}
should fix things (I should have mentioned this initially). I have this
set up as a define that so that when I compile the program under Linux the
__cdecl is removed by the preprocessor.
As you surmised, you need two global variable to make this work in the
form presented. I think once you get the compiler to recognize the two
globals the remaining errors will likely go away, (if not feel free to
post the *new* errors here ;)
regards,
--tom
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol "struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol "int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Here is the function that I have when both logmovei and g_bLogging are global in data.h and data.c
#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri
Uri Blass
 

Re: problems with compiling printlog function

Postby Tom Likens » 27 Feb 2004, 20:12

Geschrieben von: / Posted by: Tom Likens at 27 February 2004 20:12:38:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Matthias Gemuh at 27 February 2004 19:24:37:
// printing both to the logfile and to stdout or nul
void PrintLog(FILE *fp, bool bLogging, char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat); vprintf(szFormat, vargs); fflush(stdout);
if (bLogging && fp != (FILE *)NULL) { vfprintf(fp, szFormat, vargs); fflush(fp); }
va_end(vargs);
}

I don't use fastcall, so I don't need __cdecl.
Would fastcall "fasten" my program by 10% or more ?

/Matthias.
Hello Matthias,
It might help a little. I don't know if it will speed the Lion up by 10% but
you never know.
--tom
P.S. Of course, that's all we need is a Lion with sharper claws!!
Tom Likens
 

Re: problems with compiling printlog function

Postby Tom Likens » 27 Feb 2004, 20:21

Geschrieben von: / Posted by: Tom Likens at 27 February 2004 20:21:39:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 19:59:38:
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol
"struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol
"int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Here is the function that I have when both logmovei and g_bLogging are
global in data.h and data.c

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri
Unfortunately, I don't have my code in front of me but I believe what you need
to do is define your two globals in the data.c file as:
FILE *logmovei = (FILE *)NULL;
int g_bLogging = 0;
Of course, the syntax could be slightly different (for one thing since these
are globals they will be zeroed out when the program initializes anyway, but
you get the idea).
And define two extern statements in the data.h file.
extern FILE *logmovei;
extern int g_bLogging;
This should hopefully resolve your linker problems.
regards,
--tom
Tom Likens
 

Re: problems with compiling printlog function

Postby Lance Perkins » 27 Feb 2004, 20:22

Geschrieben von: / Posted by: Lance Perkins at 27 February 2004 20:22:20:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 19:59:38:

Look into your data.c to make sure that both logmovei and g_bLogging are defined (and are not just 'extern' as in your data.h).
Hey Uri,
Some answers interspersed below.
I copied the function from
http://f11.parsimony.net/forum16635/messages/61760.htm
I tried to compile it with no success.
I get one warning and 4 errors inspite of starting with 2 includes
Here is the code(defs.h and data.h are files that I include in every
file of my program and they include the global varaibles of the program.

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && fpLog != (FILE *)NULL)
{
vfprintf(fpLog, szFormat, vargs);
fflush(fpLog);
}
va_end(vargs);
}
the warning is
warning C4096: '__cdecl' must be used with '...'
The errors are that g_bLogging and fpLog are not defined.
I guess that the error means that I need to have global varaible for
integer and to use logmovei that is defined as external FILE* in data.h
and as FILE* in data.c instead of using fpLog but I first care about the
first warning.
If you are using the "fastcall" linking option under Windows it will cause
the error you're seeing. Changing the function prototype (and the actual
function) to:
void __cdecl PrintLog(const char *szFormat, ...);
void __cdecl PrintLog(const char *szFormat, ...)
{
etc.
}
should fix things (I should have mentioned this initially). I have this
set up as a define that so that when I compile the program under Linux the
__cdecl is removed by the preprocessor.
As you surmised, you need two global variable to make this work in the
form presented. I think once you get the compiler to recognize the two
globals the remaining errors will likely go away, (if not feel free to
post the *new* errors here ;)
regards,
--tom
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol "struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol "int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Here is the function that I have when both logmovei and g_bLogging are global in data.h and data.c
#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri
Lance Perkins
 

Re: problems with compiling printlog function

Postby Uri Blass » 27 Feb 2004, 20:34

Geschrieben von: / Posted by: Uri Blass at 27 February 2004 20:34:54:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Tom Likens at 27 February 2004 20:21:39:
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol
"struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol
"int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Here is the function that I have when both logmovei and g_bLogging are
global in data.h and data.c

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri
Unfortunately, I don't have my code in front of me but I believe what you need
to do is define your two globals in the data.c file as:
FILE *logmovei = (FILE *)NULL;
int g_bLogging = 0;
Of course, the syntax could be slightly different (for one thing since these
are globals they will be zeroed out when the program initializes anyway, but
you get the idea).
And define two extern statements in the data.h file.
extern FILE *logmovei;
extern int g_bLogging;
This should hopefully resolve your linker problems.
regards,
--tom
Thanks to both of you but unfortunately it did not solve the problem
I even copied what I have in data.h to data.c by copy and paste and deleted the extern to verify that I have no spelling error but the compiler continues to give me the same error.
Uri
Uri Blass
 

Re: problems with compiling printlog function

Postby Uri Blass » 27 Feb 2004, 20:42

Geschrieben von: / Posted by: Uri Blass at 27 February 2004 20:42:32:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 20:34:54:
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol
"struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol
"int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Here is the function that I have when both logmovei and g_bLogging are
global in data.h and data.c

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri
Unfortunately, I don't have my code in front of me but I believe what you need
to do is define your two globals in the data.c file as:
FILE *logmovei = (FILE *)NULL;
int g_bLogging = 0;
Of course, the syntax could be slightly different (for one thing since these
are globals they will be zeroed out when the program initializes anyway, but
you get the idea).
And define two extern statements in the data.h file.
extern FILE *logmovei;
extern int g_bLogging;
This should hopefully resolve your linker problems.
regards,
--tom
Thanks to both of you but unfortunately it did not solve the problem
I even copied what I have in data.h to data.c by copy and paste and deleted the extern to verify that I have no spelling error but the compiler continues to give me the same error.
Uri
I solved the problem
It seems that the problem was that my file was .cpp
Now when the file is .c like all other files everything is ok.
Maybe the compiler had a problem because of having one .cpp file when the other are .c files in this case.
Uri
Uri Blass
 

Re: problems with compiling printlog function

Postby Matthias Gemuh » 27 Feb 2004, 20:45

Geschrieben von: / Posted by: Matthias Gemuh at 27 February 2004 20:45:01:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Tom Likens at 27 February 2004 20:12:38:
// printing both to the logfile and to stdout or nul
void PrintLog(FILE *fp, bool bLogging, char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat); vprintf(szFormat, vargs); fflush(stdout);
if (bLogging && fp != (FILE *)NULL) { vfprintf(fp, szFormat, vargs); fflush(fp); }
va_end(vargs);
}

I don't use fastcall, so I don't need __cdecl.
Would fastcall "fasten" my program by 10% or more ?

/Matthias.
Hello Matthias,
It might help a little. I don't know if it will speed the Lion up by 10% but
you never know.
--tom
P.S. Of course, that's all we need is a Lion with sharper claws!!


OK. I shall try fastcall when number of major bugs has been reduced a bit.
/Matthias.


BigLion + Taktix
Matthias Gemuh
 

Re: problems with compiling printlog function

Postby Dieter Bürßner » 27 Feb 2004, 20:45

Geschrieben von: / Posted by: Dieter Bürßner at 27 February 2004 20:45:36:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 20:34:54:

Don't forget to #include stdio.h (with the angle brackets, I suggest to use angle brackets for other compiler supplied .h files, too, instead of the double quotes). stdio.h must be included before "extern FILE * ...".
The __cdecl stuff should not be needed.
Regards,
Dieter
Dieter Bürßner
 

Re: problems with compiling printlog function

Postby Peter Fendrich » 27 Feb 2004, 20:59

Geschrieben von: / Posted by: Peter Fendrich at 27 February 2004 20:59:11:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 19:59:38:
Hey Uri,
Some answers interspersed below.
I copied the function from
http://f11.parsimony.net/forum16635/messages/61760.htm
I tried to compile it with no success.
I get one warning and 4 errors inspite of starting with 2 includes
Here is the code(defs.h and data.h are files that I include in every
file of my program and they include the global varaibles of the program.

#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && fpLog != (FILE *)NULL)
{
vfprintf(fpLog, szFormat, vargs);
fflush(fpLog);
}
va_end(vargs);
}
the warning is
warning C4096: '__cdecl' must be used with '...'
The errors are that g_bLogging and fpLog are not defined.
I guess that the error means that I need to have global varaible for
integer and to use logmovei that is defined as external FILE* in data.h
and as FILE* in data.c instead of using fpLog but I first care about the
first warning.
If you are using the "fastcall" linking option under Windows it will cause
the error you're seeing. Changing the function prototype (and the actual
function) to:
void __cdecl PrintLog(const char *szFormat, ...);
void __cdecl PrintLog(const char *szFormat, ...)
{
etc.
}
should fix things (I should have mentioned this initially). I have this
set up as a define that so that when I compile the program under Linux the
__cdecl is removed by the preprocessor.
As you surmised, you need two global variable to make this work in the
form presented. I think once you get the compiler to recognize the two
globals the remaining errors will likely go away, (if not feel free to
post the *new* errors here ;)
regards,
--tom
Now compile is ok but I have problems with building it.

logfunctions.obj : error LNK2001: unresolved external symbol "struct _iobuf * logmovei" (?logmovei@@3PAU_iobuf@@A)
logfunctions.obj : error LNK2001: unresolved external symbol "int g_bLogging" (?g_bLogging@@3HA)
Release/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
main.exe - 3 error(s), 0 warning(s)
Uri
Here is the function that I have when both logmovei and g_bLogging are global in data.h and data.c
#include "defs.h"
#include "data.h"
#include "stdarg.h"
//printing both to the logfile and to stdout
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}
Uri
Sometimes when I get similar errors it's solved by rebuilding the whole program.
My Ms environment dont always automatically understand what modules are affected by the changes and what have to be re-compiled.
/Peter
Peter Fendrich
 

Re: problems with compiling printlog function

Postby Uri Blass » 27 Feb 2004, 21:00

Geschrieben von: / Posted by: Uri Blass at 27 February 2004 21:00:18:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Dieter Bürßner at 27 February 2004 20:45:36:
Don't forget to #include stdio.h (with the angle brackets, I suggest to use angle brackets for other compiler supplied .h files, too, instead of the double quotes). stdio.h must be included before "extern FILE * ...".
The __cdecl stuff should not be needed.
Regards,
Dieter
I have #include in my data.h that is included in the relevant file so there is no problem.
I did not try to include also stdarg.h in that file.
Every c file of movei includes stdio.h because I start it by
#include "defs.h"
#include "data.h"

I do not know if it is good programming and maybe it is better not to include stdio.h in files that I do not need it.
Uri
Uri Blass
 

Re: problems with compiling printlog function

Postby Dieter Bürßner » 28 Feb 2004, 23:31

Geschrieben von: / Posted by: Dieter Bürßner at 28 February 2004 23:31:04:
Als Antwort auf: / In reply to: Re: problems with compiling printlog function geschrieben von: / posted by: Uri Blass at 27 February 2004 21:00:18:
I have #include in my data.h that is included in the relevant file so there is no problem.
I did not try to include also stdarg.h in that file.
Every c file of movei includes stdio.h because I start it by
#include "defs.h"
#include "data.h"

I do not know if it is good programming and maybe it is better not to include stdio.h in files that I do not need it.
I guess, you really need that #include stdio.h in your data.h, because you probably have some line
extern FILE *logfp;
or similar, there. This cannot compile, if FILE is not known. So, it is really needed, more or less, that you #include stdio.h there (or your header file will not be easily usable).
It is no problem, to include the same Standard C header file twice, and I would suggest to do this even in general in such cases (it will not make a difference).
If I hade some file

#include <stdio.h>
#include "myinclude.h"
void foo(void)
{
  printf("Hello\n")&#59;
}

I would #include stdio.h, even if I knew, that myinclude.h includes that already (I might forget about that fact later), because the usage of printf() in foo asks for stdio.
Regards,
Dieter
Dieter Bürßner
 


Return to Archive (Old Parsimony Forum)

Who is online

Users browsing this forum: No registered users and 31 guests