Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recipe to build static or dynamic library? #49

Open
tpham3783 opened this issue Mar 6, 2017 · 5 comments
Open

Add recipe to build static or dynamic library? #49

tpham3783 opened this issue Mar 6, 2017 · 5 comments

Comments

@tpham3783
Copy link

Hi,

I wonder why isn't there any recipe to generate a static or dynamic library for this library? Should we add one?

@jslee02
Copy link

jslee02 commented Mar 6, 2017

According to this comment of the Author, this library is meant to be used as the source code itself rather than binaries. 😄

@tpham3783
Copy link
Author

tpham3783 commented Mar 6, 2017

Understood, but if it is a static library, it is easier for the developer to link to it. Below is a Makefile to compile the library, developers can just link to it with "-static -llodepng" :-)

PREFIX?=/usr
INSTALL?=install

SRC=$(wildcard *.cpp)

SRC:=$(filter-out lodepng_unittest.cpp,$(SRC))
SRC:=$(filter-out lodepng_benchmark.cpp,$(SRC))

OBJS=$(SRC:.cpp=.o)

CXXFLAGS:=-fPIC -Os

TARGET=liblodepng.a liblodepng.so

all: $(TARGET)
	echo "Built libraries $(TARGET) successfully."
	
liblodepng.a: $(OBJS)
	$(AR) $(ARFLAGS) $@ $^
	
	
liblodepng.so: $(OBJS)
	$(CXX) -o $@ -shared $^
	

install: $(TARGET)
	$(INSTALL) lodepng.h lodepng_util.h $(DESTDIR)/$(PREFIX)/include
	
	
clean:
	rm -f $(OBJS) $(TARGET)

@jslee02
Copy link

jslee02 commented Mar 6, 2017

It could be. @lvandeve may have the right answer for you. I just replied as this reminds me the comment. 😓

@lvandeve
Copy link
Owner

lvandeve commented Mar 7, 2017

Yes, it is only one source file and one header and is intended to be added directly as source files to your project. The source file also has no dependencies. It can also be renamed to have the .c extension to use as pure C only. There is a second source file lodepng_util but it is only needed for edge cases.

There is no makefile, it opens a whole can of worms and requires a lot of maintenance as platforms and popular make systems change. For this simple project, the actual C source is in fact simpler to be multiplatform than a makefile :)

I would suggest to integrate the source files in the build system you are using, it's only 1 file and one header after all.

@jlaumon
Copy link

jlaumon commented Jun 8, 2018

What about adding a LODEPNG_API macro to give the user the ability of adding __declspec(dllexport) if needed? (Some other one-file libraries do it that way (eg. dear imgui))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants