Solved

VC++ Link Error - Assembly and C++

Posted on 2003-11-28
6
658 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 213
Not needed 13 120
egit plugin on eclipse 8 82
"Black Box" Testing of Control System Software 2 72
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

828 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