How to import shared code from banks with ca65?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
How to import shared code from banks with ca65?
by on (#230392)
I have my boot.asm

Code:
.segment "CODE"
.include "boot_shared.inc"
.segment "VECTORS"
    .word nmi
    .word reset
    .word irq
.segment "BANK0"
.scope b2
    .include "boot_shared.inc"
    .segment "VECTORS0"
        .word nmi
        .word reset
        .word irq
.endscope


And boot_shared.inc

Code:
.import main

reset:
    ...
    lda #0
    jsr lib_SwitchBank
    jmp main

nmi:
    ...
    rti

irq:
    rti

.export lib_SwitchBank
.proc lib_SwitchBank
    and #$0F
    sta $8000
    rts
.endproc


I want somehow to import lib_SwitchBank into any bank, but instead I get "Duplicate external identifier: `lib_SwitchBank'" even though (and I might be wrong) they are on the same address... Scope doesn't seem to have. I should not have too many of those routines, but I need at least a couple. How can I correctly link it?
Re: How to import shared code from banks with ca65?
by on (#230394)
Dunno, but try removing ".export lib_SwitchBank" from boot_shared.inc and moving it to boot.asm at top-level scope.
Re: How to import shared code from banks with ca65?
by on (#230395)
Duh... Sorry, should have thought about that... Thank you!
Re: How to import shared code from banks with ca65?
by on (#230397)
Instead of including the same code multiple times in your source, shouldn't it be possible to do this with the linker config? Just define a segment that's included multiple times in the ROM image.
Re: How to import shared code from banks with ca65?
by on (#230409)
I don't think the ld65 configuration language allows a single SEGMENT to be copied into multiple MEMORY areas.