• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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

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
wewesb
Asked:
wewesb
1 Solution
 
snoeglerCommented:
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
 
wewesbAuthor Commented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now