Link errors with MFC app and non-MFC library 
Author Message
 Link errors with MFC app and non-MFC library

I have an MFC application that links with a non-MFC static
library (i.e. does not use any MFC components.)   I built
the library on my own machine and have been using it extensively
for some time now.  I recently gave the library to another developer
in my group.  When he tried to link his MFC application with my
library, he ended up getting a whole bunch of multiply-defined
symbol errors from the linker. All the symbols it complained
about where MFC methods and functions.

To fix the problem, I had to exclude nafxcw.lib from his MFC project
"Link\Input" settings.  He later found that if he rebuilt my static
library with
the "Project\Settings\General\Microsoft Foundation Classes" set
to "Use MFC in a Static Library", he could link with my static
library without errors.

There are two other static, non-MFC, libraries linked with the
MFC application (built the same way as the one in question.)
All libraries and the MFC app have been built with code generation
set to "Debug Multithreaded DLL", for Debug builds, and
"Multithreaded DLL" for Release builds.

As far as the MFC project settings go, there appears to be
no differences between his MFC settings and mine.

Does any know why we're getting these errors?

Thanks,
Dave.

--
W. Dave Rathnow
Wireless Matrix Corporation
Calgary, AB (TSE:WRX)
http://www.*-*-*.com/



Sat, 08 Mar 2003 03:00:00 GMT  
 Link errors with MFC app and non-MFC library
This sounds confusing.  I would re-build all the libraries with the same
compile and linker switches on both computers..  Additionally:
1.) Make sure you have the #ifndef and #define as the first two lines in
each header file.
2.) You cannot define a variable in a header file multiple times.  Use the
"extern" keyword, and initialize the variable in a cpp file...

Bill Cram


Quote:

> I have an MFC application that links with a non-MFC static
> library (i.e. does not use any MFC components.)   I built
> the library on my own machine and have been using it extensively
> for some time now.  I recently gave the library to another developer
> in my group.  When he tried to link his MFC application with my
> library, he ended up getting a whole bunch of multiply-defined
> symbol errors from the linker. All the symbols it complained
> about where MFC methods and functions.

> To fix the problem, I had to exclude nafxcw.lib from his MFC project
> "Link\Input" settings.  He later found that if he rebuilt my static
> library with
> the "Project\Settings\General\Microsoft Foundation Classes" set
> to "Use MFC in a Static Library", he could link with my static
> library without errors.

> There are two other static, non-MFC, libraries linked with the
> MFC application (built the same way as the one in question.)
> All libraries and the MFC app have been built with code generation
> set to "Debug Multithreaded DLL", for Debug builds, and
> "Multithreaded DLL" for Release builds.

> As far as the MFC project settings go, there appears to be
> no differences between his MFC settings and mine.

> Does any know why we're getting these errors?

> Thanks,
> Dave.

> --
> W. Dave Rathnow
> Wireless Matrix Corporation
> Calgary, AB (TSE:WRX)
> http://www.wirelessmatrixcorp.com




Sat, 08 Mar 2003 03:00:00 GMT  
 Link errors with MFC app and non-MFC library

Quote:
> This sounds confusing.  I would re-build all the libraries with the same
> compile and linker switches on both computers..

The libraries were all built with the same options.  I had to change one
option
on one of the libraries, on the second machine, to get the project to build
without errors.  I WANT to build with all the same switches on both
machines.

Quote:
> 1.) Make sure you have the #ifndef and #define as the first two lines in
> each header file.

They are MFC symbols that are causing the problem.  I haven't created
any variables, classes, function or macros that clash with MFC.  I'm also
using namespaces for my libraries so even if I had duplicate names, there
shouldn't be any duplicate name errors.

Quote:
> 2.) You cannot define a variable in a header file multiple times.  Use the
> "extern" keyword, and initialize the variable in a cpp file..

I think the compiler would've caught this long before I got the link process.
No?

Dave.

--
W. Dave Rathnow
Wireless Matrix Corporation
Calgary, AB (TSE:WRX)
http://www.wirelessmatrixcorp.com



Sat, 08 Mar 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. PRB: LNK2005 Errors When Link C Run-Time Libraries Are Linked Before MFC Libraries (Q148652)

2. set_new_handler in non MFC library called from MFC application

3. non-MFC project linking with MFC static libray

4. Calling mfc library from non-mfc program

5. Linking MFC and non-MFC Projects

6. non-MFC project linking with MFC static libray

7. Using non-MFC DLL in MFC app

8. How to add an MFC CWnd to a non-MFC app

9. using MFC in non-MFC app

10. MSVC6: Help adding MFC to non-MFC App

11. Calling MFC DLLs from a non-MFC app

12. Using non-MFC DLL in MFC app

 

 
Powered by phpBB® Forum Software