Re: C module won't link to my MFC project

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
.



Relevant Pages

  • Re: Linking multiple .LIB files for override of function
    ... The way the linker works is not just the first the .lib ... In this sense, if our client exe first calls funcoverride, it will use ... That's why linking the myspeical.lib's ... obj file ensures that myspecial.lib!funoverride is used. ...
    (microsoft.public.vc.ide_general)
  • Re: tcp/ip with msclient
    ... for DJGPP equivalent to DOS_SOCK.LIB from MS Socket Development Kit. ... I had a look at the MS Sockets Development Kit and tried to use the .lib in a test build using djgpp. ... there's no easy way to convert a .obj file to .o. ...
    (comp.os.msdos.djgpp)
  • Re: Unwanted PRIVATE symbols in masm obj file
    ... This was sort of a security issue. ... I needed to send an OBJ file to someone, ... first, assemble the file to OMF format, then give it to this BAT file: ... lib /EXTRACT:%1.obj %1.lib ...
    (comp.lang.asm.x86)
  • Re: Plese remove all referanses to HLA, please ???? Dear God. Please remove all referanses to HLA.
    ... something thatis not totally usefull for RosAsm. ... .lib and .obj files. ... As long as the creation of a asm file that was originated form a lib ... With the data acquired from a lib or obj file, the user can be able to ...
    (alt.lang.asm)