ElementsProject / ElementsProject/lightning

Support building Core Lightning as a static library for C/C++ integration

Open
#8,240 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C
Stars
3.1k
Forks
1k
Avg merge
4d 10h
Merged PRs (30d)
13

Description

It would be valuable for Core Lightning (CLN) to officially support building as a static library (.a) that can be easily linked into external C or C++ projects. This would simplify and standardize integration of CLN functionality into other codebases.

### Current Workaround
While working on integrating Core Lightning into [bitcoinfuzz](https://github.com/bitcoinfuzz/bitcoinfuzz/pull/149), I implemented a workaround by appending the following rule to the end of the Makefile:

```Make
libcln.a: libccan.a $(BITCOIN_OBJS) $(COMMON_OBJS) $(WIRE_OBJS) $(EXTERNAL_LIBS) $(CCAN_OBJS)
@$(call VERBOSE, "ar $@", $(AR) r $@ $(BITCOIN_OBJS) $(COMMON_OBJS) $(WIRE_OBJS) $(CCAN_OBJS))
@echo "Extracting external libraries..."
@for lib in ${EXTERNAL_LIBS}; do \
echo "Processing $$lib"; \
if [ -f "$$lib" ]; then \
tmpdir=$$(mktemp -d); \
echo "Created temp dir: $$tmpdir"; \
fullpath="$$(pwd)/$$lib"; \
echo "Full path: $$fullpath"; \
(cd $$tmpdir && $(AR) x "$$fullpath" && echo "Extraction completed successfully"); \
if [ -n "$$(ls -A $$tmpdir)" ]; then \
echo "Found object files: $$(ls $$tmpdir)"; \
$(AR) r $@ $$tmpdir/*.o; \
else \
echo "Warning: No object files found in $$lib"; \
fi; \
rm -rf $$tmpdir; \
else \
echo "Warning: Library $$lib not found"; \
fi; \
done
```

### Request
I believe that officially supporting static library builds would benefit many integration projects beyond bitcoinfuzz. This would provide a more maintainable and supported approach to linking CLN components into other projects.

### Potential Benefits

- Simplified integration with external C/C++ projects
- Reduced setup complexity for projects needing CLN functionality
- Better compatibility with various build systems
- Improved developer experience when incorporating CLN

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.