Solved

error Lnk2001: unresolved external symbol "void __cdecl FunctionA() "

Posted on 2004-10-07
1
1,566 Views
Last Modified: 2007-12-19
Hello,
 I was trying to build a project in VC++ environment. The project includes a .CPP file and rest all .C source files. In the .CPP source file I was trying to call a C function. While building , I was facing the Linker Error:
 
   error Lnk2001: unresolved external symbol "void __cdecl FunctionA() "

Say, FunctionA() is in the C source file.
Now , I tried to have the prototype defined for visibility in the .CPP file as :

extern "C" void FunctionA(void);

Now , Iam facing the following compile error message:

     error C2732: linkage specification contradicts earlier specification

Can , this problem be solved by other means?

Regards,
Vikram

0
Comment
Question by:itsmaddi
1 Comment
 
LVL 15

Accepted Solution

by:
efn earned 500 total points
ID: 12256768
The compiler is seeing another declaration of the same function somewhere, probably without the extern "C".  You need to make the declarations consistent or cut it down to just one declaration.  Do you have it declared in a header file as well as in the .CPP file?

There's a standard technique for coding function declarations so they can be compiled in either C or C++.

    #ifdef __cplusplus
    extern "C"
    {
    #endif
    .
    . (the declaration of C functions occurs
    .  here)
    .
    #ifdef __cplusplus
    }
    #endif

(adapted from http://www.lal.in2p3.fr/ENS/MIP/cplusplus-1.html)

The symbol __cplusplus is defined for the C++ compiler, but not the C compiler, so the C++ compiler sees the extern "C" and the C compiler doesn't.  And everyone compiles happily ever after.

--efn
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

746 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

11 Experts available now in Live!

Get 1:1 Help Now