English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 08 December 2009, 22:44   #1
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
Linking to assembler objects using C++ gcc (StormV4)

Hiya,

In theory you should just be able to add assembler sources directly to a project in StormC V4 when using the gcc compiler but that doesn't work for me. So now I'm using PhxAss to compile the assembly files to object files and adding them to my StormC project. I then have to use a special header file declaration as follows:

Code:
#define REG(reg,arg) arg __asm(#reg)
 
void setVol (REG(d0, int vol));


This works great as long as the project is in plain C but if I want to create a C++ project I get linker errors (adding extern to function definition doesn't help).

Anyone got any ideas?
NovaCoder is offline  
Old 08 December 2009, 23:03   #2
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Try adding the extern "C" before the function declaration instead, inside the C++ file from where you want to call it:

Code:
extern "C" void setVol(REG(d0, int vol));
Leffmann is offline  
Old 09 December 2009, 01:01   #3
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
I tried:

Code:
 

#ifndef __GNUC__
#define REG(reg,arg) register __##reg arg
#else
#define REG(reg,arg) arg __asm(#reg)
#endif

#ifdef __cplusplus
extern "C" {
#endif
 
 
void c2p1x1_cpu3blit1_queue (
                      REG(a0, unsigned char *c2pscreen),
                      REG(a1, unsigned char *bitplanes));
#ifdef __cplusplus
};
#endif
But it won't compile, it's giving me a parser error before '__asm'

Last edited by NovaCoder; 09 December 2009 at 01:32.
NovaCoder is offline  
Old 09 December 2009, 01:36   #4
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
The extern part is correct. Not familiar with the compiler specific __asm(#reg) and __##reg parts or StormC at all. Sorry no idea how to fix. Maybe it would be easier to use a different calling convention?
Leffmann is offline  
Old 09 December 2009, 02:27   #5
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
There's more blurb about the problem here if anyone can help....
NovaCoder is offline  
Old 09 December 2009, 03:48   #6
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
Hold the phone...

Looks like it's happy to link with a simple prototype.


Code:
extern "C" void c2p1x1_cpu3blit1_queue (
                     unsigned char *c2pscreen,
                     unsigned char *bitplanes);
Strange but true
NovaCoder is offline  
Old 09 December 2009, 19:35   #7
eLowar
Citizen of Elthesh
 
eLowar's Avatar
 
Join Date: Sep 2003
Location: UK
Posts: 949
The issue occurs due to "name mangling". C++ has a more complex type system than C, e.g. allowing function overloading, so internally it uses names that include parameter types for functions. Your names of course don't include this information (which is compiler specific), so it can't find the symbols your C++ compiler translates your function names (plus parameter types) into. extern "C" declarations just tell the C++ compiler to generate symbols using plain old, unmangled C names instead.
eLowar is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
GCC Assembler return value question... NovaCoder Coders. Asm / Hardware 0 23 June 2012 07:11
VBCC assembler linking syntax? NovaCoder Coders. General 2 20 May 2011 03:04
Assembler: Linking binaries with blink redblade Coders. General 0 29 March 2005 11:02
GCC warpos linking error? JoJo Coders. General 0 21 March 2003 00:09
two cursor objects kaare johansson support.WinUAE 1 24 December 2002 00:41

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:44.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.20886 seconds with 13 queries