08 December 2009, 22:44 | #1 |
Registered User
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? |
08 December 2009, 23:03 | #2 |
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)); |
09 December 2009, 01:01 | #3 |
Registered User
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 Last edited by NovaCoder; 09 December 2009 at 01:32. |
09 December 2009, 01:36 | #4 |
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?
|
09 December 2009, 03:48 | #6 |
Registered User
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); |
09 December 2009, 19:35 | #7 |
Citizen of Elthesh
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.
|
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 |
|
|