Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unresolved extern symbols creating a dll

Status
Not open for further replies.

joeGrammar

Programmer
Jun 4, 2001
162
CA
Hey all,

I'm trying to create a dll in Visual C++ and I'm getting some unresolved symbol errors. At first I had no idea why, but now I realize that each symbol is an extern. Anyways I started off using appwizard and I have the settings set to use mfc in a shared library. Can someone tell me how to resolve these symbols?
 
Maybe you should add some libs or dll's to linker option. Can you say which external symbol is unresolved? John Fill
1c.bmp


ivfmd@mail.md
 
They are just my own symbols. There are a few variables and some C functions for which I do use extern "C". I include the header file of the function I want to use but it still is unresolved, does this have something to do with name mangling?
 
Errors look something like this

cfgitem.obj : error LNK2001: unresolved external symbol _PassOrThrow
cfgitem.obj : error LNK2001: unresolved external symbol _CheckRowsOrThrow

Now those two are C functions being used in my C++ code, but I have a "macro" CFUNCTION declared in a header file:
cfunc.h

#ifdef __cplusplus
#define CFUNCTION extern "C"
#define NOPARMS
#else
#define CFUNCTION
#define NOPARMS void
#endif

So for these functions when declared I use

CFUNCTION LOGIC PassOrThrow( LOGIC bStrict, char *szFile, int iLine, void *stmt);

and cfunc.h is included. LOGIC is my own data type as well.

The only thing I can think of is that the names are being mangled, but why?
 
There could be many problems:

1.Take care with the '#include'.
If you include the file where the extern functions are, in another file the exported functions symbols will be unresolved.

Be more strict about includes and use:
#if !defined(symbol)
#include symbols.h
#else
#error "symbols.h already included"
#endif
and in every header file use a
#define symbol

2. look for duplicate #include in your code (I mean for the same .h file)
3. have you included all lib files required ?(for other dll's that you use)

Hope this is helpful, s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I don't think the includes is the problem, I have "guards" in each of my header files for such things, it would complain if included twice. The only unresolved symbols are my own so I'm pretty sure there should be no other libraries included.

".Take care with the '#include'.
If you include the file where the extern functions are, in another file the exported functions symbols will be unresolved"

Could you give me an example of this?
 
I mean, let's say you have class CMyApp and in, inside one member function you reference the exported function. If you put #include MyApp.h in another file your referenced function would then be unresolved.

You can check if this is true, also by declaring the functions exported in the .h file and see what you get.

Good luck,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
What if you need to reference the exported function in 2 seperate files? How would the other file "see" the function?

"I mean, let's say you have class CMyApp and in, inside one member function you reference the exported function"

I'm assuming in the above statement the function is declared in MyApp.h with the extern "C" keyword.
 
Ok this is getting strange, there are 2 functions both extern "C" from a header file which is not included anywhere in my project but the exported functions are both used in a seperate file, one is unresolved and one links fine. Does anyone know why something like this COULD happen? When I do include the header file in the other file, I get no difference. Sigh....
 
My bad, the second function wasn't referenced in the file. When it is referenced it also links with an unresolved symbol. This still doesn't make any sense though, I'm getting messages like

'CheckRowsOrThrow' undefined; assuming extern returning int

Where in fact it is extern, why wouldn't it pick up that?
 
AHA, apparently each unresolved function has __FILE__ and or __LINE__ involved in its declaration... what the heck is that?
 
put in all source files the first line:
#include"StdAfx.h" John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top