Solved

VC5: .c vs .cpp Compiling/Linking: Unresolved Externals

Posted on 1998-08-12
2
260 Views
Last Modified: 2010-04-10
I have a .c file which compiles and links fine. When I compile and link this file with the /Tp option to specify it to be compiled as a C++ file the link fails with the error: LNK2001 unresolved external symbol. The .lib which contains the implementation of the function I am trying to use matches with a .dll which was written in visual basic. Any ideas?
0
Comment
Question by:wewesb
2 Comments
 
LVL 6

Accepted Solution

by:
snoegler earned 20 total points
ID: 1170036
The point is that c++ function names get 'mangled' when building the .obj files.
'dumpbin' your c++ object file and your c object file and compare them, then you'll see
what i mean. To avoid this, declare the functions with like this:
void _declspec("C") my_func()
This tells the compiler even if compiling c++ files to use the 'c' naming scheme.
0
 

Author Comment

by:wewesb
ID: 1170037
Ah yes, that led me to a solution. I first tried void _declspec("C") my_func() but I got a syntax error complaining about "string". I changed the syntaxt to "C" void my_func() and it compiled and linked fine. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

932 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

8 Experts available now in Live!

Get 1:1 Help Now