Solved

UNICODE linkage

Posted on 1998-12-17
11
1,270 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
Comment Utility
You should also define _UNICODE.
0
 

Author Comment

by:gilg
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now