LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-01-2010, 09:11 AM   #1
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Rep: Reputation: 15
Remove duplicate entries on a row


HI,

Let's say that we have a variable LIBS:

LIBS='-lpq -lmysqlclient -lssl -lpthread -lresolv -lssl -lpthread -lresolv'

I'd want to get:

LIBS='-lpq -lmysqlclient -lssl -lpthread -lresolv'

Bear in mind that LIBS can be variable, I mean I need to drop any duplicate and only retain the last one of each different entry. And we must keep the order as is, I must not sort out them.

So, if LIBS is:

LIBS='-lpq -lmysqlclient -lpthread -lresolv -lpthread -lresolv'

I need: LIBS='-lpq -lmysqlclient -lpthread -lresolv'

Thanks in advance!!
 
Old 11-01-2010, 09:28 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by sebelk View Post
Let's say that we have a variable LIBS:

LIBS='-lpq -lmysqlclient -lssl -lpthread -lresolv -lssl -lpthread -lresolv'

I'd want to get:

LIBS='-lpq -lmysqlclient -lssl -lpthread -lresolv'
Why do you want to do that? It could break certain link dependencies - if you had "-la -lb -la" it would be turned into "-la -lb", but if libb depends on liba then it could fail to link unless you pass certain special options to the linker to iterate through libraries repeatedly (the default is to go through once, and only use libraries later in the list to resolve dependencies for the current library). This would especially be a problem when linking statically.

Is it just for interest, or do you expect some benefit from this? If the latter, I'd say don't bother - it'll cause problems while solving none.
 
Old 11-01-2010, 09:43 AM   #3
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by JohnGraham View Post
Why do you want to do that? It could break certain link dependencies - if you had "-la -lb -la" it would be turned into "-la -lb", but if libb depends on liba then it could fail to link unless you pass certain special options to the linker to iterate through libraries repeatedly (the default is to go through once, and only use libraries later in the list to resolve dependencies for the current library). This would especially be a problem when linking statically.
Thanks for see beyond that emerging problem

I don't want that -la -lb -la turn into -la -lb, but -lb -la

Quote:
Originally Posted by JohnGraham View Post
Is it just for interest, or do you expect some benefit from this? If the latter, I'd say don't bother - it'll cause problems while solving none.
Quote:
It's because I've autoconfiscated a project and found a macro ax_ext_have_lib.m4 that with its little documentation says:

AX_EXT_HAVE_LIB is identical to AC_SEARCH_LIBS with the exception that
# will add -L<directory> when looking, and use a different variable for
# each directory.
#
# Any required -L<directory> flags are added to LDFLAGS and located
# libraies are added to LIBS
#
The problem that the macro as is can only be used once, otherwise override the earlier library on LIBS, so I append as a quick and dirty workaround at the end:

Code:
LIBS="$new_libs $LIBS"
You may take a look at macro code onhttp://www.gnu.org/software/autoconf..._have_lib.html

But weirdly causes the some entries duplicated, I wonder is that is harmful. What do you think?

Thanks in advance
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove duplicate entries from first column?? kadvar Programming 2 05-12-2010 06:22 PM
removing duplicate entries shabev Linux - Enterprise 3 03-25-2008 10:36 AM
Duplicate entries in fstab jrdioko Linux - Software 3 08-14-2006 01:08 AM
Duplicate Entries OpenSuSE 10.0 TMan459 SUSE / openSUSE 3 10-19-2005 04:43 AM
ordering row entries rohr Programming 4 04-11-2005 03:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration