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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:20:47+00:00 2026-05-11T03:20:47+00:00

EDIT: I suppose I should clarify, in case it matters. I am on a

  • 0

EDIT: I suppose I should clarify, in case it matters. I am on a AIX Unix box, so I am using VAC compilers – no gnu compilers. End edit


I am pretty rusty in C/C++, so forgive me if this is a simple question.

I would like to take common functions out of a few of my C programs and put them in shared libraries or shared objects. If I was doing this in perl I would put my subs in a perl module and use that module when needed.

For the sake of an example, let’s say I have this function:

int giveInteger() {     return 1034; } 

Obviously this is not a real world example, but if I wanted to share that function, how would I proceed?

I’m pretty sure I have 2 options:

  1. Put my shared function in a file, and have it compile with my main program at compile time. If I ever make changes to my shared function, I would have to recompile my main program.
  2. Put my shared function in a file, and compile it as a shared library (if I have my terms correct), and have my main program link to that shared library. Any changes I make to my shared library (after compiling it) would be integrated into my main program at runtime without re-compiling my main program.

Am I correct on that thinking?

If so, how can I complish either/both of those methods? I’ve searched a lot and I seem to find information how how I could have my own program link to someone else’s shared library, but not how to create my own shared functions and compile them in a way I can use them in my own program.

Thanks so much!

Brian


EDIT:

Conclusion

Thanks everyone for your help! I thought I would add to this post what is working for me (for dynamic shared libraries on AIX) so that others can benefit:

I compile my shared functions:

xlc -c sharedFunctions.c -o sharedFunctions.o 

Then make it a shared object:

xlc -qmkshrobj -qexpfile=exportlist sharedFunctions.o xlc -G -o libsharedFunctions.so sharedFunctions.o  -bE:exportlist 

Then link it another program:

xlc -brtl -o mainProgram mainProgram.c  -L. -lsharedFunctions 

And another comment helped me find this link, which also helped: http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/topic/com.ibm.vacpp7a.doc/proguide/ref/compile_library.htm

Thanks again to all who helped me out!

  • 1 1 Answer
  • 2 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. 2026-05-11T03:20:48+00:00Added an answer on May 11, 2026 at 3:20 am

    Yeah you are correct. The first is called a static library, while the second is called a shared library, because the code is not bound to the executable at compile time, but everytime again when your program is loaded.

    Static library

    Compile your library’s code as follows:

    gcc -c *.c 

    The -c tells the program not to link the object file, but just leaves you with object files for each .c file that was compiled. Now, archive them into one static library:

    ar rcs libmystuff.a *.o  

    man ar will tell you what the rcs options mean. Now, libmystuff.a is a archive file (you can open it with some zip-file viewers) which contain those object files, together with an index of symbols for each object file. You can link it to your program:

    gcc *.c libmystuff.a -o myprogram 

    Now, your program is ready. Note that the order of where the static libraries appear in the command matter. See my Link order answer.

    Shared library

    For a shared library, you will create your library with

    gcc -shared -o libmystuff.so *.c 

    That’s all it takes, libmystuff.so is now a shared object file. If you want to link a program to it, you have to put it into a directory that is listed in the /etc/ld.so.conf file, or that is given by the -L switch to GCC, or listed in the LD_LIBRARY_PATH variable. When linking, you cut the lib prefix and .so suffix from the library name you tell gcc.

    gcc -L. -lmystuff *.c -o myprogram 

    Internally, gcc will just pass your arguments to the GNU linker. You can see what arguments it pass using the -### option: Gcc will print the exact arguments given to each sub process.

    For details about the linking process (how some stuff is done internally), view my Linux GCC linker answer.

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

Sidebar

Related Questions

Can you make file copying faster through multiple threading? Edit : To clarify, suppose
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT What small things which are too easy to overlook do I need to
Edit : Solved, there was a trigger with a loop on the table (read
I'd like to use Oracle's utl_match.edit_distance function. It supposed to compare two strings and

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.