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 7636125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:35:38+00:00 2026-05-31T07:35:38+00:00

My problem is fairly easy but I just don’t know how to solve it.

  • 0

My problem is fairly easy but I just don’t know how to solve it. I know how to compile and library and link against it if I’m not using a make file because then I can just call ar separately and everything goes right.

Anyway I’m using a petsc library and I’m using a makefile what they provided:

CFLAGS          = 
FFLAGS          = 
CPPFLAGS        = 
FPPFLAGS        =
LOCDIR          = /home/user/.../.../   # Working folder
EXAMPLESC       = main.cpp class.cpp        #.cpp file names here
EXAMPLESF       =
#MANSEC          = Mat I don't know what this is but it seems to work without it.

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

myProgram: main.o class.o  chkopts
    -${CLINKER}  -o myProgram main.o class.o ${PETSC_MAT_LIB}
    ${RM} main.o class.o

include ${PETSC_DIR}/conf/test

ARFLAGS will be -rv as a default so where should I provide such a information as

ar -rv libclassdll.a class.o

and where should I add -L./-lclassdll ?

I’m quite a rookie with makefiles so that’s why I’m a bit lost here :<

I tried to change the line to

myProgram: main.o class.o  chkopts
    -${CLINKER}  -o myProgram main.o class.o ${AR} libclassdll.a class.o ${PETSC_MAT_LIB}
    ${RM} main.o class.o

and then my compiling command seems to be
mpicxx -o myProgram main.o class.o /usr/bin/ar/ libclassdll.a class.o -L ( a lot of linking here ) and at least it says: g++ classdll.a no such a file or dir.

So it doesn’t generate even a lib file for me. So any ideas will be really appreciated.

A new problem when I uploaded makefile on the different machine, my current makefile looks like this

LibMyClass.so: MyClass.o  chkopts
    -${CLINKER}  -shared -Wl,-soname,${SONAME} -o ${VERS}   *.o  ${PETSC_MAT_LIB}

    mv ${VERS} ${LIBADD}
    ln -sf ${LIBADD}${VERS} ${LIBADD}${SOWOV}
    ln -sf ${LIBADD}${VERS} ${LIBADD}${SONAME}

That works on one machine but other machine gives following error

/usr/bin/ld: MyClass.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
MyClass.o: could not read symbols: Bad value

I did change the paths of course but I guess that indicates other kind of problem because even if I type “g++ -shared -Wl,-soname,libmyclass.so.1 -o libmyclass.so.1.0 MyClass.o” or “g++ -fPIC -share… ” I’ll get the same error.

  • 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-05-31T07:35:39+00:00Added an answer on May 31, 2026 at 7:35 am

    Ideally you should construct the library first, then use it, just as you would “by hand”.

    To construct (or update) the library, you need a rule something like this:

    libclassdll.a: class.o
        ar -rv libclassdll.a class.o
    

    Or more concisely, like this:

    libclassdll.a: class.o
        ar $(ARFLAGS) $@ $^
    

    Then the rule for myProgram becomes:

    # Assuming CLINKER is something civilized, like gcc
    myProgram: main.o libclassdll.a  chkopts
        -${CLINKER} -o myProgram main.o -L. -lclassdll ${PETSC_MAT_LIB}
    

    or better:

    myProgram: main.o libclassdll.a  chkopts
        -${CLINKER} -o $@ $< -L. -lclassdll ${PETSC_MAT_LIB}
    

    So in your makefile, you would replace

    myProgram: main.o class.o  chkopts
        -${CLINKER}  -o myProgram main.o class.o ${PETSC_MAT_LIB}
        ${RM} main.o class.o
    

    with

    myProgram: main.o libclassdll.a  chkopts
        -${CLINKER} -o $@ $< -L. -lclassdll ${PETSC_MAT_LIB}
    
    libclassdll.a: class.o
        ar $(ARFLAGS) $@ $^
    

    There are other refinements you can make, but that should be enough for now.

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

Sidebar

Related Questions

This is a fairly common problem, it probably has a name, I just don't
I'm sure this is a fairly trivial problem, but I'm not sure what to
I've got a, I think fairly easy question, but this is bugging me for
I believe task I am trying to accomplish is fairly easy, but I have
I (think I) know what you're thinking... not another EXC_BAD_ACCESS question but I'm really
So im sure this is probably a fairly easy question but I am stumped
I have an idea for how to solve this problem, but I wanted to
I fairly frequently match strings against regular expressions. In Java: java.util.regex.Pattern.compile(\w+).matcher(this_is).matches Ouch. Scala has
Hi all I have a (probably) simple problem but I just can't figure out
I'm a member of a small but fairly sociable online forum, and just for

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.