473,508 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static compilation to generate shared library

4 New Member
Hi,

I am not well acquainted with the gcc '-static' flag and need some help with the following problem:

1. I have a C program with various functions which I want to compile into a library. Call this func_lib.c
2. There's a separate C file logger.c which contains a function logger() which is called by each function in func_lib.c for the purpose of logging. logger() uses stdio.h for printf() etc.
3. I want to compile func_lib.c into libfuncs.so

What I'm doing as of now is:

gcc -c -static logger.c
gcc -c -static func_lib.c
gcc -static -Wall -o2 -fPIC -shared -ldl -g -o libfuncs.so logger.o func_lib.o

All compiles well and I get the .so library
But this is not doing what I want. My intention is to make libfuncs.so such that it does not depend on any other libraries like libc.so etc that is all the byte code from there is also present in this.

Also I do not want a .a file because I'm using this .so file with LD_PRELOAD
I hope I have clarified enough on the question. Please help out

Thanks in anticipation.......
Jul 15 '07 #1
1 1478
ccodehelp
4 New Member
Is the problem not well specified or the title ambiguous?

:(

Hi,

I am not well acquainted with the gcc '-static' flag and need some help with the following problem:

1. I have a C program with various functions which I want to compile into a library. Call this func_lib.c
2. There's a separate C file logger.c which contains a function logger() which is called by each function in func_lib.c for the purpose of logging. logger() uses stdio.h for printf() etc.
3. I want to compile func_lib.c into libfuncs.so

What I'm doing as of now is:

gcc -c -static logger.c
gcc -c -static func_lib.c
gcc -static -Wall -o2 -fPIC -shared -ldl -g -o libfuncs.so logger.o func_lib.o

All compiles well and I get the .so library
But this is not doing what I want. My intention is to make libfuncs.so such that it does not depend on any other libraries like libc.so etc that is all the byte code from there is also present in this.

Also I do not want a .a file because I'm using this .so file with LD_PRELOAD
I hope I have clarified enough on the question. Please help out

Thanks in anticipation.......
Jul 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2517
by: jose luis fernandez diaz | last post by:
Hi, I am reading Stroustrup's book 'C++ Programming Language'. In the 10.4.9 section (Nonlocal Store) he says: "A variable defined outside any function (that is global, namespace, and class...
1
2986
by: Torsten Mueller | last post by:
I have to create a shared library containing C++ classes with static member variables on HPUX with aCC. I can compile and link the library and a test application but when I start the program I get...
4
1855
by: Dave | last post by:
I used the following class and .aspx code below to understand how static works on variables and methods taken from...
3
1568
by: Manny Silva | last post by:
Hi, I would like to create a static library that uses and in effect adds to another static library. I could simply add functionality to the existing library, but functionally it doesn't really...
5
2933
by: Raterus | last post by:
I'm just throwing this error out for my sanity, I've seen posts about this, but never solutions. I'm using VS.NET 2003, Framework 1.1, and I'm getting a random error about every 1 out of 10 times...
15
2283
by: Notre Poubelle | last post by:
Hello, I have a large legacy MFC application. As is typical, there is an executable along with several MFC DLLs. One of these DLLs is created by staticly linking in many libraries resulting in...
18
2518
by: Ronald Bruck | last post by:
I have several routines which are used millions of times in my programs, using the Gnu multi-precision software's floating-point reals (see <http://www.swox.se/gmp>). These are of type mpf_t, and...
0
1532
by: zztlhb | last post by:
Hi, I currently hit an issue that I would like to use a function statically linked to a shared library but my program use the same function from another shared library. Here is what I do: 1. I...
17
8352
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.