logo
down
shadow

How to create a static library with a Makefile from C source code


How to create a static library with a Makefile from C source code

By : pwnedbyefa
Date : November 22 2020, 02:42 PM
seems to work fine You chain targets through prerequisites.
To get what you want (and to have make do it by default) you need to add install as a prerequisite of your all target (though we'll be renaming that in a minute) and either replace $(TARGET) in the install prerequisite with $(STATIC) or replace STATIC with TARGET in the assignment and target lines.
code :
DESTDIR=../../
PREFIX=../

STATIC=libdemo.a

CC = gcc
CFLAGS = -Wall -Winline -pipe

LDFLAGS = -L../../../lib
LIBS    = -lpthread 

SRC = demo1.c demo2.c

OBJ = $(SRC:.c=.o)

$(STATIC): $(OBJ)
        @echo "[Link (Static)]"
        @ar rcs $@ $^

.c.o:
        @echo [Compile] $<
        @$(CC) -c $(CFLAGS) $< -o $@

clean:
        rm -f $(OBJ) *~ core tags *.bak Makefile.bak libgeniePi.*

.PHONY: install
install: $(STATIC)
        @install -m 0755 $< $(DESTDIR)$(PREFIX)/lib

all: install
        $(CC) -g -Wall -o program program.c $(LDFLAGS) $(LIBS)
all: program

program: install program.c
    $(CC) -g -Wall -o $@ program.c $(LDFLAGS) $(LIBS)
all: program.c
    $(CC) -g -Wall -o $@ $< $(LDFLAGS) $(LIBS)


Share : facebook icon twitter icon
how to create a static library or framework from a already available source code in iOS

how to create a static library or framework from a already available source code in iOS


By : user3639520
Date : March 29 2020, 07:55 AM
I hope this helps . A ton of thanks to Diney Bomfim for his excellent article on how to create a framework. This is exactly what i am looking for.
EDIT - The Link is NOT working anymore...
Makefile - to create a static library

Makefile - to create a static library


By : Mike Van Maele
Date : March 29 2020, 07:55 AM
this one helps. I have two files: osm.h and osm.cpp , I believe a make file as simple as this one will do the job
code :
LIBSRC = osm.cpp
OSMLIB = libosm.a

CFLAGS = -Wall -g -O0
LOADLIBES = -L./

$(OSMLIB): $(LIBSRC)
make -pn -f /dev/null
create makefile for static library and executable simultaniously

create makefile for static library and executable simultaniously


By : user3623236
Date : March 29 2020, 07:55 AM
like below fixes the issue Make will by default process the first target in the Makefile. In your case this is the .c.o target. To make all the default target move it to the top. Many people would prefer a style where all won't do anything but rather depend on others. Something along those lines:
code :
all: $(EXECUTABLE)

$(OUT): $(OBJECTS)
    ar rcs $(OUT) $(OBJECTS)

$(EXECUTABLE): main.c $(OUT)
    (CC) -o $(EXECUTABLE) main.c $(OUT)
In a Makefile: Given a set of source files, how to I create a static library instead of an executable?

In a Makefile: Given a set of source files, how to I create a static library instead of an executable?


By : Tulasiram
Date : March 29 2020, 07:55 AM
this will help You need to build all source files into object files, and then add the object files to the archive.
For this I suggest you use the implicit rules to build just about everything.
code :
OBJ_FILES = $(SRC_FILES:.c=.o)

libfoo.a: $(OBJ_FILES)
    ar rcs libfoo.a $(OBJ_FILES)
How to create static and dynamic library in Makefile?

How to create static and dynamic library in Makefile?


By : Sofian Teja
Date : March 29 2020, 07:55 AM
this one helps. How to create dynamic and static library in Makefile. I have C codes. In inc folder there is all of header files included and outside of this folder C files included. I want to create .a and .so library.How do i include wildcard which illustrates all the files will be executed. I tried this way.
Related Posts Related Posts :
  • C: pointer to 2d array
  • How to free a pointer in a structure array?
  • gcc -O optimization: Help me understand the effect
  • Errors on code (state machine)
  • Does node equals node on a struct initializes the rest of the struct attributes?
  • C program to copy one string into other string without using library functions
  • Macro representing a pin on a microchip
  • C code workks in Mac (Darwin 13.4), but not in Linux (2.6.32)
  • How do I read this complex C declaration?
  • Reading a file with scanf and a do while loop
  • why is the recursion used in finding the factorial of a number?
  • Inverting array elements (bitwise) doesn't work
  • git blame-like annotation of source files with gcov
  • Error using pthread on Windows with Mingw
  • Why are there two different ways of initializing a pointer in C
  • Program runs too slowly with large input - C
  • Dangling pointer example confusion
  • Why is this program running when input is 1?
  • Malloc() doesn't work + char array clear
  • Reading debug registers on linux
  • Socket Programming - Server content written to Client (write())
  • Incrementing a string in C
  • what does a[0] = addr & 0xff?
  • unexpected EOF while looking for matching `'' while using execve()
  • What's the purpose of stack pointer alignment in the prologue of main()
  • Time from startup in linux kernel
  • UNIX socket connection refused
  • How to programmatically set IP address on Windows 7 using C
  • programming a gpu without using any library like cuda or opencl?
  • C "printf" Different output in Linux and Mac
  • Bit rearrangement/manipulation in C
  • How to find occurences of a digit with 4 in it within 50?
  • Read string separated by comma
  • how to optimize the C code, when m is too big, it can't operation
  • GCC Error Infinite While Loop
  • Row-major vs Column-major confusion
  • Parsing memory mapped file C
  • going out of bounds in array of structs in C
  • fprintf in do while loop wrote only one line in file C
  • Reading and Writing to Files in C
  • Changable amount of scanned numbers per line (scanf)
  • Turtle drawing fractal with openGl
  • c database program using structs
  • How to handle 3 way send() and recv() in BSD socket using C
  • 2D Array: Alphabetical Sorting in C
  • setting the size of array
  • How Do I Fix This Sorted Linked List Insertion?
  • windows mingw asterisk '*' passing by argv[1] to string
  • C - values in array overriden after leaving while loop
  • C String cropping runtime error
  • Adding custom extension to PKCS#10 request using OpenSSL (programatically)
  • Dynamically allocate enough memory on client and server receive part
  • How can I store these numbers in C?
  • Segfault at initialization of simple for loop
  • Putting a Struct into Shared Memory
  • my program overlooks 'while' loop
  • Compile without input
  • How an int can be equal to another function returning long int?
  • Generate randoms in child process
  • C strcmp behaving strangely
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co