Closed alex-tee closed 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.
there's an example here for building one (.a) from *.o files: https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s17.html
Committed changes to the build files: 69cb986d38e7723ddfe67d0f310f14a4b29a52e7 Please check whether it works for you.
Changes committed to github-issue-7 branch
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)"
other than that, it works!
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
I think there is no right way except of adding 'lib' prefix to the '.so' and '.a' file.
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
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<...>
or even just liblsp-dsp
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
Also I've added changes for #6 into this branch, too.
sweet, thanks! I think both issues are resolved now, the license headers look fine too
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
Maybe I'm doing something wrong?
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
gcc test.c -o test -Wl,-Bstatic `pkg-config --libs lsp-dsp-lib` -Wl,-Bdynamic -lm
Yes, that worked. That strange link order...
Merged all changes to master: c9b146141ec68797d35bd070328ab2e436f2bd0f
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.