Solved

VC++ Link Error - Assembly and C++

Posted on 2003-11-28
6
652 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
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.

 
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

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

23 Experts available now in Live!

Get 1:1 Help Now