Solved

VC++ Link Error - Assembly and C++

Posted on 2003-11-28
6
665 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
Starting up a Project

617 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