Skip to content

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

Open
@erickcestari

Description

@erickcestari

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, I implemented a workaround by appending the following rule to the end of the Makefile:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions