How do I link external objects?

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I have couple of source files that I want to link to a set of Arduino "Libraries" (that are actually .o files).

when run in AVRstudio (4.18b700), the linker complains it can not find the set of .o files (No such file or directory) although in the project options I declared the corresponding library search path and told it to "link with these objects".

I am confused about where the linker tries to find these files but if I declare absolute paths, only the first objects seems to be found.

The Arduino objects were compiled by Arduino-0018 ide which seems to use winavr20081205

Could anybody tell me or point me to a doc how this should work?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the files are actually .o files and not (.a) library files then you can not make the linker "consume" them as libraries.

They should be ordinary parameters to the linker, just like .o files that came out of compiling a .c source file in studio.

I am not sure if you can convince AVR Studio to do that. You might have to resort to creating your own makefile, and then either build on a command line or tell Studio to use that makefile.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan,

I wrote a post saying it wasn't possible but then tried it and it simply works (so I deleted my previous post in this thread). If you go to Project-Config Options then "Libraries" and [Add object...] and point it at a .o file then Studio is smart enough not to strip lib and .a from it and add a -l but instead it simply adds the named .o (including full path to it) to the list of other .o's in the link.

As such I'd say that what the OP is attempting will simply work. As such I'm not sure why he's got a problem at all?

One eyeopener is to look at the link line in the Build output in my case it was:

avr-gcc -mmcu=atmega168 -Wl,-Map=test.map -Wl,-section-start=.io=0x800023 test.o empty.o  "D:\sounds\avrapp\uart.o"   -lm  -o test.elf

where "D:\sounds\avrapp\uart.o" was the .o I had pointed it towards. (and the -lm is there because, as always, I always list libm.a too)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

it simply adds the named .o (including full path to it)

Did you give the path explicitly (in some way, eg by browsing to it)? Or are you saying that even for .o files added this way, Studio uses the lib path(s)?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

one of my problems is that the library settings dialog generates object references without a path (when I select from the left pane).

When I put in absolute paths via the appropriate button it seems to only link the first one. It goes like this:

avr-g++ -mmcu=atmega32 -Wl,-Map=automaat.map injection.o logger.o Menu.o nunchuck.o radio.o ReadSecret.o rtc.o SerialPort.o Timerstuff.o AutoData.o automaat.o Display.o ds18b20.o eeprom.o gps.o  "pins_arduino.c.o" "Print.cpp.o" "Tone.cpp.o" "WInterrupts.c.
o" "wiring.c.o" "wiring_analog.c.o" "wiring_digital.c.o" "wiring_pulse.c.o" "wiring_shift.c.o" "WMath.cpp.o" "HardwareSerial.o" "C:\Documents and Settings\twinkel\Mijn documenten\AVRstudio\automaat\atmega32\main.o" "C:\Documents and Settings\twinkel\Mijn documenten\AVRstudio\automaat\atmega32\HardwareSerial.o" "C:\Documents and Settings\twinkel\Mijn documenten\AVRstudio\automaat\wiring_analog.c.o"  -L"C:\Documents and Settings\twinkel\Mijn documenten\AVRstudio\automaat\default" -L"C:\Documents and Settings\
twinkel\Mijn documenten\AVRstudio\automaat\."   -o automaat.elf

avr-g++.exe: pins_arduino.c.o: No such file or directory
avr-g++.exe: Print.cpp.o: No such file or directory
avr-g++.exe: Tone.cpp.o: No such file or directory
avr-g++.exe: WInterrupts.c.o: No such file or directory
avr-g++.exe: wiring.c.o: No such file or directory
avr-g++.exe: wiring_analog.c.o: No such file or directory

Main.o is seen here but HardwareSerial is not. The long list of .o files starting with "pins_arduino.c.o" can not be found at all, even if they are in the search path, in ./ or in ./default.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have spaces in the path names. Unless you can find a way to get Studio to quote them, move the files to somewhere other than "Documents and settings"

@Johan the [Add Object...] leads to a file browser and what you select is specified with its full drive/path.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, the spaces in the path names was a silly oversight on my part.

The other thing is that the library settings in project options suggests you can link *.o files by selecting them from the left pane. The library search path option does not facilitate "finding" .o files as Johan said.

For this, you have to use the "add object" button. In my case 20 times (since I was so silly starting my project with Arduino). The resulting absolute file/path names can than only be read in the Makefile, because they are too long.

My resulting code has now grown from 24706 (command line) to 48150 (studio), so it now compiles until the end but this size of code can not be loaded in my atmega32. Enough reason for further investigation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The size problem was solved by adding -Wl--gcc-sections as ONE OPTION in the Custom Compilation options of the linker. Resulting code was halved because it left out unreferenced code from various libraries.