Discuss HELP: assembly & C linking woes.... in the C Programming forum on Dev Shed. HELP: assembly & C linking woes.... C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 18
Time spent in forums: 4 h 36 m 6 sec
Reputation Power: 0
HELP: assembly & C linking woes....
I am having problems linking an assembly object with my C object files. Am getting:
Linker Warning: DOSSEG directive ignored in module asm.asm
Linker Error: Undefined symbol _ASMClsV in module main.c
Linker Error: Undefined symbol VADDR in module asm.asm
In my asm.asm file I've got:
DOSSEG
.MODEL huge
.386
.DATA
EXTRN vaddr : word;
.CODE
PUBLIC ASMClsV
ASMClsV PROC Near
;bla bla
ASMClsV EndP
In main.c I've got:
extern void ASMClsV();
Am trying to link using Borland C++ 4.5 since my source files are all 16-bit. I successfully linked the same asm.asm file with a 16-bit pascal object using Turbo Pascal 7.0. Why can't I link using Borland C++ 4.5 to a 16-bit C file?
Also, I used Microsoft Macro Assembler 5. Should I use Turbo Assembler?
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 8,978
Time spent in forums: 1 Month 2 Weeks 6 Days 21 h 44 m 27 sec
Reputation Power: 3561
C compilers usually mangle a function name by adding an _ to the front of each function name and variable. This has been traditionally done by C compilers since the days of K&R. You can do one of two things:
1. Rename your asm function as _ASMCIsV and reassemble it
2. Go to your Options --> Compiler --> Advanced Code Generation and turn off the Generate Underbars option and then rebuild your C files completely.
Either way, it should link correctly now
Note that C++ mangling rules differ from C rules. So, if your compiler thinks it is compiling a C++ file, it will mangle the function names differently. To control this, google for 'extern "C" '
__________________ Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne Diary of a first time dog owner <-- my cousin's blog
Posts: 18
Time spent in forums: 4 h 36 m 6 sec
Reputation Power: 0
Excellent! I managed to get the C & assembly files recognise each others variables & functions. Thanks to Scorpions4ever for telling me about C mangles variable & function names by prefixing an underscore in front. Now I get a different problem:
Linker Error: Fixup overflow at _TEXT:0002, target = vaddr in module asm.asm
...
It appears there's a linker error line for each of my variables surrounded by [ ], eg.
ASMClsV PROC Near
mov es, [vaddr]
; bla bla
ASMClsV EndP
Posts: 18
Time spent in forums: 4 h 36 m 6 sec
Reputation Power: 0
I read the cool document about Fixup Overflow at /~jakov/community.borland.com/15961.html but still unsuccessful. I fixed this problem myself by moving the variables from the C file to assembly file.
C file:
extern unsigned short vaddr; //Pascal word type
extern long AsmY; //Pascal integer type
extern void *ScrOfsPtr; //Pascal pointer type
Assembly file:
.DATA
PUBLIC vaddr, AsmY, ScrOfsPtr
vaddr label word
AsmY label word
ScrOfsPtr label dword
Now I don't know why I need the label before word/dword. What does that mean? And is that correct corresponding to the C & Pascal types?