Solved

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

Posted on 2004-10-07
1
1,570 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.

809 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