Re: C module won't link to my MFC project
- From: Tage Korsdal Nielsen <tkn@xxxxxxxxxx>
- Date: Wed, 29 Mar 2006 22:15:38 +0200
Thanx alot!
Your tip combined with testing for __cplusplus define solved this!
:-)
Best regards
Tage
JongAm Park wrote:
Hi..
So, you added an obj file or a lib file which is a C-module into your VC 2003 project. Do I understand your situation correctly?
I guess that the C-module is compiled with a "C" compiler or at least with "C" calling convention.
Then in the object file, whether it is obj or lib, your function will be written "crcCalc". However when the caller in your VC project file try calling it, it searches a function with its name as ?crcCalc@@YAGPAXG0@Z. As you can see, there is strange characters are added to the end of crcCalc. ( and actually ? in front of it also. )
So, the linker can't find the crcCalc function.
To be able to call the "C" function, you need to embrace the lines in the header file this way.
#ifndef CRC_H
#define CRC_H
#include "comdef.h"
extern "C"
{
uint16 crcCalc( void *buf, uint16 length, void *crcAdr );
}
#endif
or simply, attach the extern "C" in front of the unit16 crcCalc(....);
Then the linker find it in "C" way.
If you want to know it more, try searching "calling convention" in the MSDN reference library.
You may need "stdcall" also, depending on your situation.
Hope this helps.
JongAm Park
Tage Korsdal Nielsen wrote:
Hi
I'm using VC 2003.
I have a small C-module for CRC calculation that I use in three projects: An embedded project, Linux/Cygwin and now in my MFC project.
I have added the file to the project, and turned off "precompiled headers".
It compiles ok from the IDE, and the .obj file is in my output directory, but the linker complaints with this:
Linking...
M2MClient.obj : error LNK2019: unresolved external symbol "unsigned short __cdecl crcCalc(void *,unsigned short,void *)" (?crcCalc@@YAGPAXG0@Z) referenced in function "private: unsigned long __thiscall CM2MClient::routePkg(struct CmClsPkg *,unsigned short)" (?routePkg@CM2MClient@@AAEKPAUCmClsPkg@@G@Z)
Debug/leaxm2m.exe : fatal error LNK1120: 1 unresolved externals
The header file is:
#ifndef CRC_H
#define CRC_H
#include "comdef.h"
uint16 crcCalc( void *buf, uint16 length, void *crcAdr );
#endif
What can be wrong?
Rgds
Tage
- References:
- C module won't link to my MFC project
- From: Tage Korsdal Nielsen
- Re: C module won't link to my MFC project
- From: JongAm Park
- C module won't link to my MFC project
- Prev by Date: Re: C module won't link to my MFC project
- Next by Date: Re: I need source code of a large Visual C++ project
- Previous by thread: Re: C module won't link to my MFC project
- Next by thread: Re: I need source code of a large Visual C++ project
- Index(es):
Relevant Pages
|