Solved

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

Posted on 1998-08-12
2
257 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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.

763 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

11 Experts available now in Live!

Get 1:1 Help Now