Thursday, May 2, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 990  / 3 Years ago, sat, august 7, 2021, 3:16:39

I'm trying to link all *.o files from another folder and would like to in my Makefile do something like;



g++ *.o (folder/*.o and not folder/main.o) -o bin


Is there someway I can use somekind of simple regex here?


More From » command-line

 Answers
7

Try g++ *.o $( echo folder/*.o |tr ' ' "
" | egrep -v folder/main.o )
, assuming none of folder/*.o have SPACES in their names.



Here's how it works:



echo folder/*.o produces a space-separated list of the filenames, with the directory.

tr ' ' "
"
changes all the spaces to newlines (giving us one filename per line, which makes egrep happy.

egrep -v folder/main.o eliminates the undesired filename from this list.

$() puts the rest of the filenames on the command line. Since $IFS defaults to SPACE, TAB, NEWLINE, we don't have to tr them back to spaces.


[#40911] Sunday, August 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anatta

Total Points: 326
Total Questions: 128
Total Answers: 96

Location: Jordan
Member since Sun, Jun 26, 2022
2 Years ago
anatta questions
Sun, Jul 17, 22, 07:13, 2 Years ago
Sun, Jun 6, 21, 12:17, 3 Years ago
Sat, Jun 12, 21, 20:43, 3 Years ago
Thu, Jan 13, 22, 20:49, 2 Years ago
Sat, Jun 5, 21, 05:39, 3 Years ago
;