Solved

UNICODE linkage

Posted on 1998-12-17
11
1,278 Views
Last Modified: 2013-12-03
I have a VC++5 project creating a dll. I define the following: WIN32,_DEBUG,_WINDOWS,_WINDLL,_USRDLL,UNICODE and I don't specify any lib.

My problem is I fail with linkage errors:
uafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___wargv
uafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc

any ideas?
0
Comment
Question by:gilg
  • 5
  • 5
11 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1417429
You should also define _UNICODE.
0
 

Author Comment

by:gilg
ID: 1417430
It doesn't work. Please notice that I already defined UNICODE. Is there a difference between this and _UNICODE?
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 150 total points
ID: 1417431
You're building with _USRDLL, which means you're writing a DLL.  DLLs don't have command-lines, so you won't see __argv or __argc, period.

B ekiM

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 11

Expert Comment

by:mikeblas
ID: 1417432
Normally, you only need to define UNICODE--certainly, for an MFC app, it's all that's required.  _UNICODE is used by the Windows headers, while MFC And the C Runtimes headers use UNICODE.

There's 2 or three spots in the headers where the headers make sure that defining one defines the other.

B ekiM

0
 

Author Comment

by:gilg
ID: 1417433
So, why do I get the linkage errors? I actually solved the problem by defining _AFXDLL or by linkaging statically to MFC. I still don't understand where did the problem came from in the first place.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1417434
That error means you reference the symbols, but they're not defined in any of the libraries or OBJ files you've given the linker.

B ekiM

0
 

Author Comment

by:gilg
ID: 1417435
But I'm not referencing those symbols.
A) I know I'm not
B) They don't appear in the source browser
C) The linkage error specifies the origin of the reference as: uafxcwd.lib(appcore.obj) (see in the body of the question).
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1417436
A) You must be.  The linker doesn't randomly decide to run off and look at symbols you're not at least indirectly using.

B) The source browser uses a completely separate code path and symbol table.

C) Right.  You're touching something in UAFXCWD.LIB that's, in turn, using the symbols.

If you can break it down into specific questions, I can probably explain away the holes in your knowledge. But I'm not prepared to offer a complete tutorial on how the linker works.

B ekiM


0
 

Author Comment

by:gilg
ID: 1417437
What do you mean indirectly using? How can I touch something in UAFXCWD.lib?

Can you illustrate this to me with a code sample?

Again, defining _AFXDLL solved the problem with no code modifications. As I understand it, MFC's h files generate some use of the erroneus variables when _AFXDLL is not defined. What I really want to know is what is the logical reason for this.
I have some notion that it has something to do with Extension DLLs or just MFC DLLs but I'm not sure.

If this is to vague to answer, just say so and I'll grade your answer.

Thanks for the efforts already made,
Gili
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1417438
UAFXCWD.LIB is the static debug build of MFC. You touch stuff in it by referencing any MFC-provided symbol. You cause the linker to consider the library the second you #include <afx.h> with _DEBUG and _UNICODE defined, and without _AFXDLL defined.

Check out all the #pragma comment(lib) directives at the beginning of AFX.H.

The logical reason is that _AFXDLL and _USRDLL cause MFC to behave differently. That behaviour is so different that you'll actually link with different libraries, and those different libraries reference external symbols in different patterns.

You really need to learn more about the linker; it's not magic, and it's something that you'll use several times every single day while you're writing code.

B ekiM

0
 

Author Comment

by:gilg
ID: 1417439
Thanks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question