Solved

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

Posted on 1998-08-12
2
262 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
[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
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

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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