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

Shared lib #182

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

CC ?= gcc
CXX ?= g++
AR ?= ar

override CFLAGS := -W -Wall -Wextra -ansi -pedantic -O3 -Wno-unused-function $(CFLAGS)
override CXXFLAGS := -W -Wall -Wextra -ansi -pedantic -O3 $(CXXFLAGS)
override CFLAGS := -W -Wall -Wextra -ansi -pedantic -O3 -Wno-unused-function -fPIC $(CFLAGS)
override CXXFLAGS := -W -Wall -Wextra -ansi -pedantic -O3 -fPIC $(CXXFLAGS)

all: unittest benchmark pngdetail showpng
all: unittest benchmark pngdetail showpng liblodepng.so liblodepng.a

%.o: %.cpp
@mkdir -p `dirname $@`
Expand All @@ -30,5 +31,11 @@ pngdetail: lodepng.o lodepng_util.o pngdetail.o
showpng: lodepng.o examples/example_sdl.o
$(CXX) -I ./ $^ $(CXXFLAGS) -lSDL2 -o $@

liblodepng.so: lodepng.o
$(CXX) $(CXXFLAGS) $^ -shared -o $@

liblodepng.a: lodepng.o
$(AR) rcs $@ $^

clean:
rm -f unittest benchmark pngdetail showpng lodepng_unittest.o lodepng_benchmark.o lodepng.o lodepng_util.o pngdetail.o examples/example_sdl.o
22 changes: 22 additions & 0 deletions lodepng.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ freely, subject to the following restrictions:

#include <string.h> /*for size_t*/

#ifdef __cplusplus
extern "C" {
#endif
extern const char* LODEPNG_VERSION_STRING;

/*
Expand Down Expand Up @@ -102,6 +105,10 @@ or comment out LODEPNG_COMPILE_CRC below*/
#define LODEPNG_COMPILE_CRC
#endif

#ifdef __cplusplus
}
#endif

/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/
#ifdef __cplusplus
#ifndef LODEPNG_NO_COMPILE_CPP
Expand All @@ -116,6 +123,10 @@ or comment out LODEPNG_COMPILE_CPP below*/
#include <string>
#endif /*LODEPNG_COMPILE_CPP*/

#ifdef __cplusplus
extern "C" {
#endif

#ifdef LODEPNG_COMPILE_PNG
/*The PNG color types (also used for raw image).*/
typedef enum LodePNGColorType {
Expand Down Expand Up @@ -246,6 +257,9 @@ unsigned lodepng_encode24_file(const char* filename,
#endif /*LODEPNG_COMPILE_DISK*/
#endif /*LODEPNG_COMPILE_ENCODER*/

#ifdef __cplusplus
}
#endif

#ifdef LODEPNG_COMPILE_CPP
namespace lodepng {
Expand Down Expand Up @@ -303,6 +317,10 @@ unsigned encode(const std::string& filename,
#endif /*LODEPNG_COMPILE_CPP*/
#endif /*LODEPNG_COMPILE_PNG*/

#ifdef __cplusplus
extern "C" {
#endif

#ifdef LODEPNG_COMPILE_ERROR_TEXT
/*Returns an English description of the numerical error code.*/
const char* lodepng_error_text(unsigned code);
Expand Down Expand Up @@ -1089,6 +1107,10 @@ to handle such files and encode in-memory
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename);
#endif /*LODEPNG_COMPILE_DISK*/

#ifdef __cplusplus
}
#endif

#ifdef LODEPNG_COMPILE_CPP
/* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */
namespace lodepng {
Expand Down