Linked Script Wildcards?

Programming, for all ages and all languages.
Post Reply
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Linked Script Wildcards?

Post by Creature »

I have a (possibly) rather stupid question about linker scripts. I was wondering if there was a way to use wildcards in input files. Suppose I have a directory with 2 object files 'main.o' and 'print.o', is there anyway I could do something like:

Code: Select all

SECTIONS
{
   /* ... */
}

INPUT(*.o)
or something similar? It's really a pain to add an object file each time I create a new source file. So I figured there had to be some way of doing it.

Thanks,
Creature
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Re: Linked Script Wildcards?

Post by frank »

I know that you can use *.o on the command line. I'm not sure about within linker scripts, you will just have to try for yourself.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Linked Script Wildcards?

Post by Combuster »

Otherwise, there's still the shell thing, like:
cat link.ld.in > link.ld
find blabla | grep lala | sed hobo >> link.ld
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Linked Script Wildcards?

Post by Solar »

The behaviour is not documented in the LD manual, so I wouldn't rely on it even if it works...

Which begs the question, why would you want to include both files in the linker script, instead of the LD command line?
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Linked Script Wildcards?

Post by Combuster »

(stab at the darkness) djgpp, 255 char command line
Before I forget, did you look at the Makefile tutorial, so to not miss out on the obvious?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Linked Script Wildcards?

Post by DeletedAccount »

Hi,
It can be easily automated :D . Recursively scan the directory and generate the file :) . I can send you the code if interested .


Regards
Sandeep
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Linked Script Wildcards?

Post by Creature »

Solar wrote:The behaviour is not documented in the LD manual, so I wouldn't rely on it even if it works...

Which begs the question, why would you want to include both files in the linker script, instead of the LD command line?
I was giving an example, I don't really have 2 object files in my linker script, there are many more and it's a pain to add them to the command line either way. I'm amazed that they didn't implement something automated into the linker script.

I guess I could do what Shrek proposed, but no thanks for the application, I can write it myself ;).

Thanks for your help :).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Linked Script Wildcards?

Post by DeletedAccount »

Hi,
I was just recommending a quick fix , so that the 'process' is not getting affected :D . I would advise you to meditate further on the questions of other posters as well :D .

Regards
Shrek
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Linked Script Wildcards?

Post by Creature »

Yes, I'll take a look at the potential solutions, thanks to all of you :).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Linked Script Wildcards?

Post by Solar »

Creature wrote:I was giving an example, I don't really have 2 object files in my linker script, there are many more and it's a pain to add them to the command line either way. I'm amazed that they didn't implement something automated into the linker script.
Because this is the classic scenario for a Makefile using "find" to get the list of source (and object) files... try the Makefile tutorial in the Wiki for a guide on how to do that.
I guess I could do what Shrek proposed, but no thanks for the application, I can write it myself ;).
Toying with the linker script is the wrong solution for this (very valid) problem, IMHO.
Every good solution is obvious once you've found it.
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Linked Script Wildcards?

Post by Creature »

Well I had more of an idea to use the linker script without the input files and write some kind of application that grabs all the object files in the specified directory and adds them to the 'ld' command line one by one. Though tedious and possibly slow, it still does the trick. I was trying to stay away from makefiles (as I don't really know a lot about them). Guess it's time to see how they work too, had to happen someday ;).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Linked Script Wildcards?

Post by DeletedAccount »

Solar wrote:
Toying with the linker script is the wrong solution for this (very valid) problem, IMHO.
But sometimes , when things are broken don't fix them :twisted: . It can save you hours of explanation later .

Your are correct solar , I did say it is a quick fix , and not a good one

Regards
Shrek
Post Reply