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

Duplicate symbols with libbwa #693

Open
rob-p opened this issue Apr 25, 2018 · 5 comments · May be fixed by lh3/bwa#346
Open

Duplicate symbols with libbwa #693

rob-p opened this issue Apr 25, 2018 · 5 comments · May be fixed by lh3/bwa#346

Comments

@rob-p
Copy link

rob-p commented Apr 25, 2018

Hi,

First, thank you all for htslib. This is an amazing resource and incredibly useful library. I have a project that includes uses both libbwa and libhts. However both of these (linked statically) seem to include the same symbol _ksprintf. The specific error is:

duplicate symbol _ksprintf in:
    ../../external/install/lib/libhts.a(kstring.o)
    ../../external/install/lib/libbwa.a(kstring.o)
ld: 1 duplicate symbol for architecture x86_64

any suggestions about how to avoid this?

Thanks!
Rob

@daviesrob
Copy link
Member

I'm having trouble getting this to happen, at least with my small test program. How did you build htslib and bwa, and what are you trying to build that joins them together?

@valeriuo
Copy link
Contributor

Also, are you building from Xcode and do you have -ObjC set in your linker flags?

@rob-p
Copy link
Author

rob-p commented Apr 25, 2018

Hi @daviesrob,

Thanks for the quick reply. I build htslib with a regular ./configure --prefix=<INSTALL_DIR> && make install. I am building these together for our project Salmon. We use some internal functions of bwa, so we depend on libbwa.a. Currently, we use Staden's io_lib for SAM and BAM parsing, but I would like to move to htslib, as it is a more canonical SAM/BAM parser, with more features, that is updated more frequently. The build process first builds libbwa.a then builds libhts.a, and then they are both linked together when building the Salmon binary. This problem popped up only when attempting to switch to htslib, as io_lib does not include the _ksprintf symbols.

@valeriuo : I am building from the command line using CMake and Make (in this case with the default OSX compiler --- i.e. Apple Clang). I don't have -ObjC set. All of the code I'm building is either C or C++ (specifically C++11).

Thanks,
Rob

@rob-p
Copy link
Author

rob-p commented Apr 26, 2018

Hi all,

I realized the awesome SeqLib library links both libbwa and libhts. So, I dug into things a little bit, and realized they actually had to hack the kstring.c/kstring.h in bwa as so. The fact that you have to actually modify the source of one or the other library is not the most satisfying solution, but it does, of course, work in my case.

Best,
Rob

@jmarshall
Copy link
Member

Seeing as HTSlib is a widely-used library packaged and distributed in both shared and static form (and is probably the canonical source of third-party use of shared klib functionality), while libbwa.a is a non-installed intermediate file produced while building the bwa executable which a handful of other projects reach into and link against, it seems to me that the appropriate place to work around this is in libbwa.

Ideally bwa's build system could be patched so you could (optionally) compile bwa's source files against HTSlib's edition of the klib headers and omit the k*.o files supplied by HTSlib from libbwa.a. This is complicated by the fact that HTSlib provides only a subset of the klib facilities used by bwa.

The easy way to work around this would be to patch bwa's klib header like this:

diff --git bwa/kstring.h bwa/kstring.h
index fe7fa95..13d374f 100644
--- bwa/kstring.h.orig
+++ bwa/kstring.h
@@ -20,6 +20,11 @@ typedef struct __kstring_t {
 } kstring_t;
 #endif
 
+// Avoid conflicting with HTSlib's kstring.c functions, to enable
+// linking against both libbwa and libhts. We #define each function
+// in BWA's kstring.c, which is currently just one function.
+#define ksprintf bwa_ksprintf
+
 static inline void ks_resize(kstring_t *s, size_t size)
 {
        if (s->m < size) {

Salmon could achieve this without patching bwa source code at all by building its copy of libbwa.a with -Dksprintf=bwa_ksprintf in the compilation flags.

daviesrob added a commit to daviesrob/htslib that referenced this issue Jun 10, 2019
Prevent clashes with other libraries that use the Attactive Chaos
version of kstring.h by putting an hts_ prefix in front of all
the external symbols.  The API is preserved by adding static
inline wrappers around the renamed symbols.

Relatively trivial functions ksprintf(), kstrstr() and kstrnstr()
are moved into the header file.

Fixes samtools#693 (Duplicate symbols with libbwa)
jmarshall added a commit to jmarshall/bwa that referenced this issue Mar 7, 2022
Make ksprintf() static inline in kstring.h, so that it (like the other
bwa/kstring.h functions) won't conflict with similar HTSlib functions.
Instead implement it and kvsprintf() in terms of a new bwa_kvsprintf()
function. Fixes samtools/htslib#693.
jmarshall added a commit to jmarshall/bwa that referenced this issue Mar 18, 2024
Make ksprintf() static inline in kstring.h, so that it (like the other
bwa/kstring.h functions) won't conflict with similar HTSlib functions.
Instead implement it and kvsprintf() in terms of a new bwa_kvsprintf()
function. Fixes samtools/htslib#693.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants