Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-07
1
Medium Priority
?
1,588 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

610 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