Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Writing MakeFile for generating a .so file

Posted on 1998-12-16
16
Medium Priority
?
621 Views
Last Modified: 2013-12-26
I need to write a makefile which creates a .so file
from .cpp files. Can somebody help me in providing me with this sample makefile.

Please also provide me with links to help me in writing makefiles

I tried doing a man but it it is too complicated for me.
A tutorial would be helpfull.
0
Comment
Question by:vresh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
  • +2
16 Comments
 
LVL 3

Expert Comment

by:elfie
ID: 1294877
when using gcc compiler

compile object with options ggc -fPIC

When build ing the .so combine all .o files into an so file, using option -G for ld. so it will be ld -G all_o_files -o file.so


0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294878
which platform?
0
 

Author Comment

by:vresh
ID: 1294879
Platform is Solaris 2.6
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vresh
ID: 1294880
Platform is Solaris 2.6
Elfie, I also require to know how to write a make file.... Thanks
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294881
file.o: file.c
    cc -fPIC -c $< -o $@

libxxx.so: file.o
    ld -B symbolic  -o $@ $<
0
 

Author Comment

by:vresh
ID: 1294882
I require a sample make file to do it and
when i use ld it starts giving me errors like
Undefined                       first referenced
 symbol                             in file
__builtin_vec_new                   cstring.o

Sorry to reject your answer
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294883
You need to pass more information (post Makefile).
Is builtin_vec_new  a function which you have defined in your .c file?
0
 
LVL 3

Expert Comment

by:elfie
ID: 1294884
ahoffman,

for making an .so doesn't you need to specify the -B option?


   -G           In dynamic mode only, produce a shared  object.
                 Undefined symbols are allowed.


0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294885
I agree, elfie.
I meant  ld -dy , sorry (options have changed due to different OS releases):
0
 
LVL 3

Expert Comment

by:elfie
ID: 1294886
If the function builtin_vec_new is present in a file (or .so) you added to your link command, try changing the order of the file

if you have a line like
ld -o prog library.so file1.0 file2.o,

change it into
ld -o prog file1.o file2.o library.so


If you are using 'ld' to build the program, you need to specify a n umber of system libraries also, so for building your it's better to use 'cc', so easier is
cc -o prog file1.o file2.o library.so



0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294887
hmm, elfie,
order of libs and/.o files should not be essential while using .so libs, .o files are searched first, then all libs
That's one of the advantages of shared objects ;-)
(but ld may have changed its algorithm, I don't know ...)
0
 
LVL 3

Expert Comment

by:elfie
ID: 1294888
we once had problems (on HP-UX 9.x) that the order of libs linking libs could influence the behavior of programs.

In case where a routine resides in two libraries, it took the first instance, and then search further for other called routines.

Probably not the case here, but ...
0
 

Expert Comment

by:tangyw
ID: 1294889
How about using ar command?
please using
%man ar
to see the detail.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294890
tangyw, we're talking about .so
0
 

Accepted Solution

by:
svedagiri earned 120 total points
ID: 1294891
Since you say that your knowledge on
writing make files are limited, Here is how you have to write you makefile
Actually I am re-iterating what elfie and hoffmann into  the follwing

Copy the following to Makefile
******************************
SO = your.so
OBJ = something.o
CPPS = something.cpp
something.o: $(CPPS)
        gcc -fPIC -c $(CPPS) -o $@
        ld -G $@ -o $(SO)
*******************************

Please remember that before gcc and ld you
have to give tab characters (when you copy this it might
result to blank, just remove the blanks and add a tab)

Hope this is helpfull
0
 

Author Comment

by:vresh
ID: 1294892
It worked but where can I find help on writing makefiles

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question