Solved

VC++ Link Error - Assembly and C++

Posted on 2003-11-28
6
650 Views
Last Modified: 2008-03-17
Using Visual C++ 6.0 I am able to compile my files fine, but get the following error when trying to link:

fringe.obj : error LNK2001: unresolved external symbol _StringBack

fringe.cpp calls a function _StringBack which is defined in the assembly file asm.asm and has the header file asm.hpp.  
I have #include "asm.hpp" in fringe.cpp
I have extern "C"  void StringBack(); in asm.hpp
The beginning of asm.asm is as follows:
.386
ifdef VC
.MODEL      FLAT,C
else
.MODEL      FLAT,SYSCALL
endif
This file also contains the assembly definition for StringBack.
The assembly code compiles fine.  I am using masm32 to compile it.  In VC++ I compile it using the following command.  Maybe I'm missing a switch?
c:\masm32\bin\ml /c $(inputpath)

I get an asm.obj file in the directory with all the other .obj files for the project.  This file has the information that fringe.cpp needs, but some how the linker isn't finding it.  

I am not that familiar with visual studios so I have a strong feeling that it is some setting that I have wrong.  Thanks for the help!
0
Comment
Question by:enviornment
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 9840802
Alas, it's insufficient just to have the .obj in the same directory, you must explicitly include it in the project via menu item: Project/Add to project/Files...
0
 

Author Comment

by:enviornment
ID: 9840813
Okay, the file is added to the project now, but I have the same error.  
0
 
LVL 22

Accepted Solution

by:
cookre earned 125 total points
ID: 9840943
Does the ASM code export the entry point with something like:

_StringBack PROC C PASCAL EXPORT prologue info


See if this helps.  It's for MS MASM 6, but most assemblers have something similar.

http://doc.ddart.net/asm/Microsoft_MASM_Programmers_Guide_v6.1/Chap_07.htm
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:SubodhKatiyar
ID: 9842008
it is very simple
1 : add your obj from asm into library you can use tlib or any other library compiler and while doing a link provide reference of the library .
2: or you can provide the reference of obj file to be included in your exe during link , check for the option of the linker as i don't work with ms linker, specify the obj file you want to explic refer to and it will add the code from obj in the final exe, and don't worry about the extern thing your c program needs to know the location of the asm subroutine not the other way so go ahead it will link properly with commandline.
0
 

Author Comment

by:enviornment
ID: 9842826
Thanks for the link!  The following paragraph shed some light on things:

"The C and STDCALL langtype prefixes an underscore to the procedure name when the procedure’s scope is PUBLIC or EXPORT and places the first parameter lowest on the stack. SYSCALL is equivalent to the C calling convention with no underscore prefixed to the procedure’s name. "

Since the linker was looking for _StringBack and the name of the function was StringBack.. and I was using SYSCALL which doesn't prefix the name with an _ I was getting link errors.  I changed STDCALL to C and it linked.  

Only problem is I had a list of about 50 of those identical link errors from different files.. I cleared up about a dozen of them with that change.  But.. the other ones are trying to reference a library.. but I can't go in and change the library.  I think it is the same problem with the _.  I wonder if there is a setting in Visual Studios that would make this change for the whole project?  Hmm.
0
 
LVL 22

Expert Comment

by:cookre
ID: 9843289
I believe there's an equate/equivalence/alias/define you can give the liknker.

I have to go do some chores right now, but I'll look it up later.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Order table with macro 3 75
array6 challenfge 6 63
strDist challenge 35 84
pairs challenge 5 44
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

12 Experts available now in Live!

Get 1:1 Help Now