Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:07:48+00:00 2026-06-18T10:07:48+00:00

I have a specific problem, but let me first take a stab at formulating

  • 0

I have a specific problem, but let me first take a stab at formulating it in a general way:

I am working in Linux (openSUSE 12.2 to be exact). The toolchain is quite standard, using make, OpenMPI mpicc (which uses GCC) and so on.

My problem is essentially that I am given a string of link commands as a macro in a makefile (i.e., “-lsomelib -L/some/path -lanotherlib” and so on). I want to create a library (let’s call it libmine) which uses these libraries, and I don’t want the consumers of libmine to have to care about what libraries I use (i.e., they should only have to do -lmine and not care about -lsomelib and so on).


Specifically I am dealing with petsc, which strongly suggests that I use one of its makefiles as a template instead of trying to roll my own. A minimal makefile for my purposes would be:

include ${PETSC_DIR}/conf/variables                                             
include ${PETSC_DIR}/conf/rules                                                 

mine.o: mine.c chkopts                                                            
        ${CC} ${CFLAGS} ${PETSC_CCPPFLAGS} -o mine.o -c mine.c ${PETSC_KSP_LIB}

Here mine.c is the source code for my library, and ${PETSC_KSP_LIB} is a string containing link instructions. On my machine it is specifically:

-L/usr/local/petsc/petsc-3.3-p5_user0/linux-gnu-user0/lib -lpetsc -lX11 -lpthread -Wl,-rpath,/usr/local/atlas -L/usr/local/atlas -llapack -lblas -L/usr/lib64/mpi/gcc/openmpi/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.7 -L/usr/local/petsc/petsc-3.3-p5_user0 -L/opt/AMDAPP/lib/x86_64 -L/usr/x86_64-suse-linux/lib -lmpi_f90 -lmpi_f77 -lgfortran -lm -lgfortran -lm -lgfortran -lm -lm -lquadmath -lm -ldl -lmpi -lnsl -lutil -lgcc_s -lpthread -ldl

These libraries are mostly static libraries (though there are presumably some dynamic ones in there as well).

I am looking for a way to have mine.o (or a finished library libmine.a) contain all of the necessary information so that when some other application that uses libmine is compiled, it only needs to link to libmine, not to the whole host of libraries that is listed in ${PETSC_KSP_LIB}.

I would hope that this is easy to do(?), but I am very shaky on the whole linking process really. Would it for example be easier to do if all the libraries were either static or dynamic? Also note that it is not necessary for me to include dynamic libraries statically, as for example adding a folder to LD_LIBRARY_PATH is not a problem at all. The essential part is that I should not have to worry about the list of libraries used by my petsc-based library when I use said library in other project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:07:49+00:00Added an answer on June 18, 2026 at 10:07 am

    Converting a shared library into a static library is non-trivial.

    To combine several static libraries into one, just unpack them and then build the new one (crude but effective):

    ar -xv somelib.a
    ar -xv anotherlib.a
    ...
    
    ar -r libmine.a *.o
    

    I have heard of a more elegant solution in one step, but I’d like to test it before I endorse it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen some related questions but none focusing on the specific problem I
I have no problem to download the content of a specific URL. But I
first I have to admit this might be a pretty specific problem. In a
I have a problem with my tableview. Let me first sketch the situation. I
I have a problem in my MATLAB code. Let me first give you some
and pardon my english I have a specific problem with Chrome browser, just in
I have a quite specific problem. I created a webapp and want to have
I have run into a bit of a problem here: I had a problem-specific
I have a problem to load specific div element and show on my page
We have a problem in a specific server. All plus signs posted to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.