473,549 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1941
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.new s.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*@RnEeMtOsVe Et.co.yu> napisal w
wiadomosci news:3F******** ******@RnEeMtOs VeEt.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****@NoOneKn ows.de> napisał w wiadomo¶ci
news:eo******** ******@TK2MSFTN GP12.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.new s.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******@nospa m.mvps.org> napisał w
wiadomo¶ci news:OR******** *****@TK2MSFTNG P10.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*@RnEeMtOsVe Et.co.yu> napisal w
wiadomosci news:3F******** ******@RnEeMtOs VeEt.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_inclu ded
#define lib1016_h_inclu ded

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,arg s);
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.nos pam> napisał w wiadomo¶ci
news:#K******** ******@TK2MSFTN GP12.phx.gbl...
j23 wrote: The following compiles & links without error:

// lib1016.h

#ifndef lib1016_h_inclu ded
#define lib1016_h_inclu ded

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,arg s);
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.li b", add library to
client1016 project - it compiles but linker reports an unresolved external
error. It's interesting that if I add "lib1016.ob j" 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\jter m\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\Micro soft.NET\Framew ork\v1.1.4322\m scorlib.dll" /FU
"D:\WINNT\Micro soft.NET\Framew ork\v1.1.4322\S ystem.dll" /FU
"D:\WINNT\Micro soft.NET\Framew ork\v1.1.4322\S ystem.Data.dll" /Zl
for test application:
/Od /AI "C:\dotnet\jter m\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\cli ent1016.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1720
by: SB | last post by:
Ok, very simple problem. I'm trying to update a value by calling a function using pass by reference, but it does not update the value. In short, the value I'm trying to update is balance, which is a private member of the class Account. I have a public function called getBalance(). I have another public function called deposit, which I pass the...
8
2941
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int p3); The parameters here can be read either in the forward order from p1 till p3 or reverse order from p3 till p1. Can anyone explain what is the...
4
2389
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
6
1873
by: yezi | last post by:
Hi : I code a program by c called "inter". I have another program called "end" Can I code in "end " to use the syscall ( "inter") ? If Yes , which kind of command format should I write? thanks for any comments.
2
4432
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
39
19579
by: Martin Jřrgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
7
1896
by: Kenneth Brody | last post by:
The recent thread on "query about main()" got me thinking... As I recall, calling a function with the wrong parameters causes undefined behavior. (These all assume that no prototype of foo() is in scope.) For example: ==== fileA.c
11
1665
by: Russ P. | last post by:
I am baffled about why my exception messages are not displaying properly. I have a class that represents physical scalars with units. If I type I should get something like this: scalar.InconsistentUnits: 3 s, 4 m
10
3240
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a programming system places on how a procedure is called and how data is passed between a calling program and procedures are called calling conventions"
1
2753
by: JohnCox | last post by:
I have a simple Win32 DLL I wrote named "SimpleLib" that exports two functions. It is written in C++ and compiled with __stdcall (/Gz) and with the preprocessor definition _MBCS (not Unicode). The first function is called "StrFirst" and takes in a LPTSTR as the first parameter and a long as the second, like this: SIMPLELIB_API int...
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7462
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.