libStatGen icon indicating copy to clipboard operation
libStatGen copied to clipboard

Multiple definition errors

Open hannespetur opened this issue 7 years ago • 5 comments

Hey there, I am working on a program which both depends on libStatGen and HTSLib. When linking to both libraries I get the following errors:

/.../statgen/libStatGen.a(knetfile.o): In function `kftp_connect':
knetfile.c:(.text+0x320): multiple definition of `kftp_connect'
/.../htslib/libhts.a(knetfile.o):/.../htslib/knetfile.c:271: first defined here
/.../statgen/libStatGen.a(knetfile.o): In function `kftp_reconnect':
knetfile.c:(.text+0x530): multiple definition of `kftp_reconnect'
/.../htslib/libhts.a(knetfile.o):/.../htslib/knetfile.c:282: first defined here
/.../statgen/libStatGen.a(knetfile.o): In function `kftp_parse_url':
knetfile.c:(.text+0x760): multiple definition of `kftp_parse_url'
/.../htslib/libhts.a(knetfile.o):/.../htslib/knetfile.c:294: first defined here
/.../statgen/libStatGen.a(knetfile.o): In function `kftp_connect_file':
knetfile.c:(.text+0x8c0): multiple definition of `kftp_connect_file'

... and so on.

This is of course because both libraries have the same function names. Would it be possible to make it so both libraries can be linked without errors? As a short-term solution I simply renamed all these functions in libStatGen by adding 2 at the end. I could make a pull request, but perhaps you have other solutions in mind.

Thank you for your contributions.

hannespetur avatar Jul 28 '16 09:07 hannespetur

The appropriate fix for this and other naming conflicts is to wrap all of libStatGen in a namespace. This would be a breaking change but could be set up to be enabled with a preprocessor definition.

jonathonl avatar Jul 28 '16 12:07 jonathonl

I support the idea of wrapping libStatGen in a namespace. It fixes conflicts and makes your code clearer to read, especially if you are using many different libraries. However, in my case the naming conflicts originate from a C file and C doesn't support namespace resolution.

hannespetur avatar Jul 28 '16 14:07 hannespetur

Just curious, is it possible to use libStatGen alone? Or, what function you will need to use is in htslib but not in libStatGen?

zhanxw avatar Jul 29 '16 03:07 zhanxw

Not always, there are some differences. The API is quite different, and in my opinion much clearer in libStatGen. But it is also missing some functionality, for example I don't see any support for BCF or CRAM.

hannespetur avatar Aug 01 '16 22:08 hannespetur

You are correct, libStatGen does not support BCF or CRAM. It is a goal to someday support them (probably by incorporating htslib to handle those - ideally wrapping to maintain the libStatGen API).
Those conflicts you are seeing are actually from files that originally came from samtools that are now in both libStatGen & htslib.
I haven't looked at htslib in a while (I only work part time now), but if there hasn't been much change between the samtools version and the htslib version, libStatGen could point to the htslib version of the files if the user is also compiling with htslib.

mktrost avatar Aug 04 '16 03:08 mktrost