Solved

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

895 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

14 Experts available now in Live!

Get 1:1 Help Now