lsp-plugins / lsp-dsp-lib

DSP library for signal processing
GNU Lesser General Public License v3.0
68 stars 18 forks source link

add option to build static lib #7

Closed alex-tee closed 4 years ago

alex-tee commented 4 years ago

It looks like the makefile only produces a shared lib. Is it possible to add an option for static lib as well? That would be useful for making plugins self-contained when using this in plugins.

sadko4u commented 4 years ago

I think yes, it is possible.

Currently you may just take the *.o file from the .build directory and link it with your project but I believe it is not a good solution.

I just need to learn how to build static libraries.

alex-tee commented 4 years ago

there's an example here for building one (.a) from *.o files: https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s17.html

sadko4u commented 4 years ago

Committed changes to the build files: 69cb986d38e7723ddfe67d0f310f14a4b29a52e7 Please check whether it works for you.

sadko4u commented 4 years ago

Changes committed to github-issue-7 branch

alex-tee commented 4 years ago

this doesn't work properly with pkgconfig. this fixes it:

diff --git a/src/Makefile b/src/Makefile
index 9137ed3..4d883f9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -155,7 +155,7 @@ $(ARTIFACT_PC):
        @echo "Description: $($(ARTIFACT_VARS)_DESC)" >> "$(ARTIFACT_PC)"
        @echo "Version: $($(ARTIFACT_VARS)_VERSION)" >> "$(ARTIFACT_PC)"
        @echo "Cflags: -I\$${includedir}" >> "$(ARTIFACT_PC)"
-       @echo "Libs: -L\$${libdir} -l:$(notdir $(ARTIFACT_LIBLINK))" >> "$(ARTIFACT_PC)"
+       @echo "Libs: -L\$${libdir} -l$(notdir $($(ARTIFACT_VARS)_NAME))" >> "$(ARTIFACT_PC)"

 install: all
        @echo "Installing $($(ARTIFACT_VARS)_NAME)"
alex-tee commented 4 years ago

other than that, it works!

sadko4u commented 4 years ago

Hmm, for me this change does not work well:

gcc `pkg-config --libs lsp-dsp-lib` test.c 
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -llsp-dsp-lib
collect2: error: ld returned 1 exit status
sadko4u commented 4 years ago

I think there is no right way except of adding 'lib' prefix to the '.so' and '.a' file.

alex-tee commented 4 years ago

I don't think so, most libraries do not use the extension there (check in your /usr/lib/pkgconfig to see examples). i'm investigating this too now

alex-tee commented 4 years ago

ah the files need to start with lib. this is the standard, and -l expects the library to start with lib, so liblsp-dsp-lib<...>

alex-tee commented 4 years ago

or even just liblsp-dsp

sadko4u commented 4 years ago

I've ended with 'liblsp-dsp-lib'. Changes committed to the branch. Now it works:

> gcc `pkg-config --libs lsp-dsp-lib` test.c -o test
> ./test 
Architecture:   x86_64
Processor:      AMD Ryzen 7 2700 Eight-Core Processor
Model:          vendor=AMD, family=0x17, model=0x8
Features:       FPU CMOV MMX FXSAVE SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 SSE4A XSAVE FMA3 AVX AVX2
sadko4u commented 4 years ago

Also I've added changes for #6 into this branch, too.

alex-tee commented 4 years ago

sweet, thanks! I think both issues are resolved now, the license headers look fine too

sadko4u commented 4 years ago

Hmm, I'm trying to statically link, seems to not working still:

> gcc -Wl,-Bstatic `pkg-config --libs lsp-dsp-lib` -Wl,-Bdynamic test.c -o test
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /tmp/ccsgOmfv.o: in function `main':
test.c:(.text+0x1e): undefined reference to `lsp_dsp_init'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: test.c:(.text+0x25): undefined reference to `lsp_dsp_info'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: test.c:(.text+0xb9): undefined reference to `lsp_dsp_start'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: test.c:(.text+0xc9): undefined reference to `lsp_dsp_fill_zero'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: test.c:(.text+0xe1): undefined reference to `lsp_dsp_finish'
collect2: error: ld returned 1 exit status
sadko4u commented 4 years ago

Maybe I'm doing something wrong?

alex-tee commented 4 years ago

I'm using meson with static: true on the dependency and it seems like it detects the .a file and passes its path to gcc. i'm investigating now about running gcc directly

alex-tee commented 4 years ago
gcc test.c -o test -Wl,-Bstatic `pkg-config --libs lsp-dsp-lib` -Wl,-Bdynamic -lm
sadko4u commented 4 years ago

Yes, that worked. That strange link order...

sadko4u commented 4 years ago

Merged all changes to master: c9b146141ec68797d35bd070328ab2e436f2bd0f