problem with calling function with '...' argument

  • Thread starter Thread starter j23
  • Start date Start date
J

j23

I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It's intersting that if I
put function xxx(...) to apptest.cpp file - there is no problem.
 
j23 said:
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

[...]

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It's intersting that if I
put function xxx(...) to apptest.cpp file - there is no problem.

Well, have you included testlib.lib in your project? Is the function
xxx exported in the library?

Another thing, are you absolutely sure about va_start(args, buf)? It
doesn't look standard enough to me (buf should be a parameter of xxx).
 
j23 said:
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It's intersting
that if I put function xxx(...) to apptest.cpp file - there is no
problem.

As posted, this code is illegal - anything could happen, including failing
to link, or misbehaving in any way at runtime. When using an elipsis in a
parameter list, the elipsis must come last, and must be preceeded by a named
parameter of non-reference type.

That the compiler accepts the above is an error in the compiler - it's
strictly illegal according to the C and C++ standards. (Is it really what
you compiled, or is something missing from the above?)

-cd
 
Uzytkownik "Mihajlo Cvetanovic said:
j23 said:
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

[...]

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It's intersting that if I
put function xxx(...) to apptest.cpp file - there is no problem.

Well, have you included testlib.lib in your project? Is the function
xxx exported in the library?

Yes, testlib.lib is icncluded.
Another thing, are you absolutely sure about va_start(args, buf)? It
doesn't look standard enough to me (buf should be a parameter of xxx).

It doesn't matter if I use va_start or not - I add va_start to avoid
compilation warning. If I commnet this line problem is the same.
 
U¿ytkownik "Axel Dahmen said:
what does your testlib.h look like?

testlib.h it's only one line:

void xxx(...);
-----------------------------------------
j23 said:
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It's intersting that
if
I
put function xxx(...) to apptest.cpp file - there is no problem.
 
U¿ytkownik "Carl Daniel said:
j23 said:
I have library (static) testlib.cpp:
#include <stdarg.h>
void xxx(...)
{
char buf[100];
va_list args;
va_start(args, buf);
va_end(args);
}

and simple program apptest.cpp:

#include "testlib.h"
int main()
{
char ala[100];
char ola[100];
xxx(ala, ola);
return 0;
}

There is no compilation error, but linker reports error: "unresolved
external symbol "void __cdecl xxx(...)".
Do you have any idea how to resolve this problem. It's intersting
that if I put function xxx(...) to apptest.cpp file - there is no
problem.

As posted, this code is illegal - anything could happen, including failing
to link, or misbehaving in any way at runtime. When using an elipsis in a
parameter list, the elipsis must come last, and must be preceeded by a named
parameter of non-reference type.

when I used function like this:

void xxx(char *format ...);
or void xxx(char *format, ...);

and there was the same error. Function - void xxx(...) is the result of my
experiments...
That the compiler accepts the above is an error in the compiler - it's
strictly illegal according to the C and C++ standards. (Is it really what
you compiled, or is something missing from the above?)

As I wrote above compiler (MS VC++ 7.0) reports no errors, I know that it's
illegal in C++, but if I use legal definitions the error is the same:
"unresolved external symbol "void __cdecl xxx(char *, ...)".
 
j23 said:
Yes, testlib.lib is icncluded.

testlib probably doesn't have a function you're supposed to link to. A
common mistake is to build a lib, update a header file (.h) in another
project, but fail to update the library file (.lib) in the same
project. So the compiler sees a function and the linker does not.
 
j23 said:
when I used function like this:

void xxx(char *format ...);
or void xxx(char *format, ...);

and there was the same error. Function - void xxx(...) is the result
of my experiments...

The following compiles & links without error:

// lib1016.h

#ifndef lib1016_h_included
#define lib1016_h_included

extern void xxx(const char* ...);

#endif

// lib1016.cpp

#include "lib1016.h"
#include <stdarg.h>
#include <stdio.h>

void xxx(const char* fmt ...)
{
va_list args;
va_start (args, fmt);
vprintf(fmt,args);
va_end(args);
}

// Client1016.cpp

#include "lib1016.h"

int main(int argc, char* argv[])
{
xxx("argc %d, argv %p",argc,argv);
}

Copy the above text into three files (as indicated by the comments), compile
with

cl client1016.cpp lib1016.cpp

If you're getting unresolved external errors from the linker, there's
something else about your project that's making the functions incompatible.
How are you compiling the library? The test program? Use dumpbin /symbols
on the two .obj files to see how 'xxx' is decorated in each - is one C++
decorated and one undecorated? Are the calling conventions different?

-cd
 
U¿ytkownik "Carl Daniel [VC++ MVP]"
j23 wrote:
The following compiles & links without error:

// lib1016.h

#ifndef lib1016_h_included
#define lib1016_h_included

extern void xxx(const char* ...);

#endif

// lib1016.cpp

#include "lib1016.h"
#include <stdarg.h>
#include <stdio.h>

void xxx(const char* fmt ...)
{
va_list args;
va_start (args, fmt);
vprintf(fmt,args);
va_end(args);
}

// Client1016.cpp

#include "lib1016.h"

int main(int argc, char* argv[])
{
xxx("argc %d, argv %p",argc,argv);
}

Copy the above text into three files (as indicated by the comments), compile
with

cl client1016.cpp lib1016.cpp

Yes these files compiles & links without error, but only when I include them
into one projects. When I create library "lib1016.lib", add library to
client1016 project - it compiles but linker reports an unresolved external
error. It's interesting that if I add "lib1016.obj" to client1016 project
linker reports no error!
If you're getting unresolved external errors from the linker, there's
something else about your project that's making the functions
incompatible.

The projects was created using standard VS creator (.NET Console
application, .NET Class library)
How are you compiling the library? The test program?

I use standard options (set by Visual Studio .NET 2003 creator) - the only
thing I change was to "don't use precompiled header"

- Calling convention: __cdecl (/Gd)
- Compile as C++ Code (/TP)
- Compile as managed: Assembly Support (/clr)
- Debug Information Format: Program Database (/Zi)
- Optimization: Disabled (/Od)
- Runtime library: Multi-threaded Debug (/MTd)

there are full command lines:
for library:
/Od /AI "C:\dotnet\jterm\Debug" /D "WIN32" /D "_DEBUG" /D "_MBCS" /FD /EHsc
/MTd /GS /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Zi /clr /TP /FU
"D:\WINNT\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll" /FU
"D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" /FU
"D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /Zl
for test application:
/Od /AI "C:\dotnet\jterm\Debug" /D "WIN32" /D "_DEBUG" /D "_MBCS" /FD /EHsc
/MTd /GS /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Zi /clr /TP
for linker:
/OUT:"C:\dotnet\jterm\Debug\client1016.exe" /INCREMENTAL /NOLOGO /DEBUG
/ASSEMBLYDEBUG /PDB:"C:\dotnet\jterm\Debug/client1016.pdb" /FIXED:No
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Use dumpbin /symbols
on the two .obj files to see how 'xxx' is decorated in each - is one C++
decorated and one undecorated? Are the calling conventions different?

No, calling conventions are the same. I run dumpbin tool on lib1016.lib file
and function __cdecl xxx(const char* ...) is in library!
 
j23 said:
The projects was created using standard VS creator (.NET Console
application, .NET Class library)

That's likely the problem right there - a .NET class library is a DLL, not a
static library, and you've not exported anything from the DLL. Do you need
this code to be built as managed code (that runs on the CLR and requires the
..NET framework)? If not, create the projects as "Win32 Console Application"
and "Win32 Project", changing the project type on the Application
Properties page of the "Win32 Application Wizard" dialog to "Static
Library".

-cd
 
U¿ytkownik "Carl Daniel [VC++ MVP]"
That's likely the problem right there - a .NET class library is a DLL, not a
static library, and you've not exported anything from the DLL.

I know that .NET class library is a DLL, but I changed "Configuration Type"
to the "static library". It works for all my libraries exept this one which
uses function with '...' argument.
Do you need
this code to be built as managed code (that runs on the CLR and requires the
.NET framework)?

Yes, I need this code to build as managed code. Is this possible?
 
Back
Top