Forum: Compiler & IDEs .S-Files mit avr-eclipse


von Gerry (Gast)


Lesenswert?

Hallo,

ich möchte in einem C++-Projekt, welches ich für den ATMEGA32 mit 
avr-eclipse entwickle, Assembler-Quellcode in .S-Files einsetzen.

Nun weiß ich aber nicht, wie ich dem Linker in der Eclipse-IDE 
verklickern soll, dass er diesen Quellcode einbindet.


Das Projekt enthält die Datei main.cpp:
1
extern void asmfn (void);
2
3
int main (void)
4
{
5
  //asmfn();
6
  while(1);
7
  return 0;
8
}

sowie asmpart.S:
1
 .section .text
2
 .global asmfn
3
4
asmfn:  
5
    ret

Beide Dateien werden kompiliert, es wird asmpart.o sowie main.o erzeugt, 
und die asmfn taucht auch im .map-File mit dem Verweis auf asmpart.o 
auf.
Wenn ich jedoch die Auskommentierung vor "asmfm()" entferne, erhalte ich 
die Fehlermeldung:
1
Building target: asmtest.elf
2
Invoking: AVR C++ Linker
3
avr-g++ -Wl,-Map,asmtest.map,--cref -mmcu=atmega32 -o"asmtest.elf"  ./asmpart.o ./main.o   
4
./main.o: In function `main':
5
../main.cpp:5: undefined reference to `asmfn()'
6
make: *** [asmtest.elf] Error 1

Und wenn ich unter Project->Properties->AC/C++ Build->Settings->AVR C++ 
Linker->Objects die Datei asmpart.o manuell unter "Other Objects" 
eintrage, erhalte ich die Fehlermeldung
1
Invoking: AVR C++ Linker
2
avr-g++ -Wl,-Map,asmtest.map,--cref -mmcu=atmega32 -o"asmtest.elf"  ./asmpart.o ./main.o  asmpart.o 
3
asmpart.o: In function `asmfn':
4
../asmpart.S:(.text+0x0): multiple definition of `asmfn'
5
./asmpart.o:../asmpart.S:(.text+0x0): first defined here
6
./main.o: In function `main':
7
../main.cpp:5: undefined reference to `asmfn()'
8
make: *** [asmtest.elf] Error 1

Kann mir bitte jemand einen Tip geben?

von Oliver (Gast)


Lesenswert?

Bei mir gehts völlig problemlos. Aktuulltes Eclipse-plugin, und 
WinAVR20071221. main.c und asmpart.S als sourcefiles.
1
extern void asmfn (void);
geht auch ohne extern.

Oliver
1
**** Build of configuration Debug for project test ****
2
3
make all 
4
Building file: ../asmpart.S
5
Invoking: AVR Assembler
6
avr-gcc -x assembler-with-cpp -g2 -gstabs -mmcu=atmega16 -MMD -MP -MF"asmpart.d" -MT"asmpart.d" -c -o"asmpart.o" "../asmpart.S"
7
Finished building: ../asmpart.S
8
 
9
Building file: ../main.c
10
Invoking: AVR Compiler
11
avr-gcc -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -mmcu=atmega16 -DF_CPU=1000000UL -MMD -MP -MF"main.d" -MT"main.d" -c -o"main.o" "../main.c"
12
Finished building: ../main.c
13
 
14
Building target: test.elf
15
Invoking: AVR C Linker
16
avr-gcc -Wl,-Map,test.map -mmcu=atmega16 -o"test.elf"  ./asmpart.o ./main.o   
17
Finished building target: test.elf
18
 
19
Invoking: AVR Create Extended Listing
20
avr-objdump -h -S test.elf  >"test.lss"
21
Finished building: test.lss
22
 
23
Invoking: Print Size
24
avr-size --format=avr --mcu=atmega16 test.elf
25
AVR Memory Usage
26
----------------
27
Device: atmega16
28
29
Program:     164 bytes (1.0% Full)
30
(.text + .data + .bootloader)
31
32
Data:          0 bytes (0.0% Full)
33
(.data + .bss + .noinit)
34
35
36
Finished building: sizedummy

von Oliver (Gast)


Lesenswert?

Bei mir gehts völlig problemlos. Aktuellstes Eclipse-plugin, und 
WinAVR20071221. main.c und asmpart.S als sourcefiles.
1
extern void asmfn (void);
geht auch ohne extern.

Oliver
1
**** Build of configuration Debug for project test ****
2
3
make all 
4
Building file: ../asmpart.S
5
Invoking: AVR Assembler
6
avr-gcc -x assembler-with-cpp -g2 -gstabs -mmcu=atmega16 -MMD -MP -MF"asmpart.d" -MT"asmpart.d" -c -o"asmpart.o" "../asmpart.S"
7
Finished building: ../asmpart.S
8
 
9
Building file: ../main.c
10
Invoking: AVR Compiler
11
avr-gcc -Wall -g2 -gstabs -O0 -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -mmcu=atmega16 -DF_CPU=1000000UL -MMD -MP -MF"main.d" -MT"main.d" -c -o"main.o" "../main.c"
12
Finished building: ../main.c
13
 
14
Building target: test.elf
15
Invoking: AVR C Linker
16
avr-gcc -Wl,-Map,test.map -mmcu=atmega16 -o"test.elf"  ./asmpart.o ./main.o   
17
Finished building target: test.elf
18
 
19
Invoking: AVR Create Extended Listing
20
avr-objdump -h -S test.elf  >"test.lss"
21
Finished building: test.lss
22
 
23
Invoking: Print Size
24
avr-size --format=avr --mcu=atmega16 test.elf
25
AVR Memory Usage
26
----------------
27
Device: atmega16
28
29
Program:     164 bytes (1.0% Full)
30
(.text + .data + .bootloader)
31
32
Data:          0 bytes (0.0% Full)
33
(.data + .bss + .noinit)
34
35
36
Finished building: sizedummy

von Oliver (Gast)


Lesenswert?

Nachtrag: Hatte übersehen, daß es um C++ geht.

[/c]extern "C" void asmfn (void);[c]

tuts.

Oliver

von Gerry (Gast)


Lesenswert?

Hallo,

herzlichen Dank Oliver, jetzt gehts! Das sind Fehler, die kann man 
tagelang suchen, wenn man einmal auf der falschen Fährte ist.

Danke.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.