Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VC++ Link Error - Assembly and C++

Posted on 2003-11-28
6
Medium Priority
?
670 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 500 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Make the most of your online learning experience.
Simple Linear Regression
Six Sigma Control Plans

688 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