Solved

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

Posted on 2004-10-07
1
1,574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

749 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