469,282 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

problem with calling function with '...' argument

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.
Nov 16 '05 #1
11 1711
j23 wrote:
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).

Nov 16 '05 #2
what does your testlib.h look like?

-----------------------------------------
"j23" <wi************@supra.com.pl> wrote in message
news:bm**********@atlantis.news.tpi.pl...
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.

Nov 16 '05 #3
j23 wrote:
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
Nov 16 '05 #4
j23

Uzytkownik "Mihajlo Cvetanovic" <ma*@RnEeMtOsVeEt.co.yu> napisal w
wiadomosci news:3F**************@RnEeMtOsVeEt.co.yu...
j23 wrote:
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.
Nov 16 '05 #5
j23

Użytkownik "Axel Dahmen" <No****@NoOneKnows.de> napisał w wiadomości
news:eo**************@TK2MSFTNGP12.phx.gbl...
what does your testlib.h look like?
testlib.h it's only one line:

void xxx(...);

-----------------------------------------
"j23" <wi************@supra.com.pl> wrote in message
news:bm**********@atlantis.news.tpi.pl...
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.


Nov 16 '05 #6
j23

Użytkownik "Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> napisał w
wiadomości news:OR*************@TK2MSFTNGP10.phx.gbl...
j23 wrote:
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 *, ...)".
Nov 16 '05 #7
j23 wrote:
Uzytkownik "Mihajlo Cvetanovic" <ma*@RnEeMtOsVeEt.co.yu> napisal w
wiadomosci news:3F**************@RnEeMtOsVeEt.co.yu...

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


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.

Nov 16 '05 #8
j23 wrote:
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


Nov 16 '05 #9
j23

Użytkownik "Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospam > napisał w wiadomości
news:#K**************@TK2MSFTNGP12.phx.gbl...
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\mscorl ib.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!
Nov 16 '05 #10
j23 wrote:
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
Nov 16 '05 #11
j23

Użytkownik "Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospam > napisał w wiadomości
news:un**************@TK2MSFTNGP11.phx.gbl...
j23 wrote:
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.
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?
Nov 16 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Muthu | last post: by
4 posts views Thread by Leslaw Bieniasz | last post: by
6 posts views Thread by yezi | last post: by
2 posts views Thread by ajikoe | last post: by
39 posts views Thread by Martin Jřrgensen | last post: by
7 posts views Thread by Kenneth Brody | last post: by
11 posts views Thread by Russ P. | last post: by
10 posts views Thread by sulekhasweety | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.