-
Notifications
You must be signed in to change notification settings - Fork 443
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
Compiling with clang on Windows does not work #1433
Comments
I suspect this is a new clang warning that has appeared in clang 14. I don't think we've tested that yet. It looks like it was released in March 2022. My local MSYS build has Clang-13.0, but I see at https://packages.msys2.org/package/mingw-w64-x86_64-clang there is a newer one available. I'll explore to see how to persuade it to upgrade (pacman can't see the new package currently). Edit: I did work out how to install clang-14, but I now see it fails locally with clang-13 too. I'll look into a fix. |
This is just a generic Clang thing, which is basically incompatible with our Windows symbol exporting. See these two examples.
The correction is to have the attribute on both function declarations and definitions:
Practically speaking, as far as htslib goes this is done via the I've seen this done elsewhere by manipulating the header files so during compilation there is an This is rather messy, and it's quite a bit of work to do and get correct. For now I think the only work around is to use gcc, but I'll leave this issue open as it's a real problem that we need to work on. |
Ah a correction. I should have done Well, my description of how it should be done turns out to actually be how it is done. The The problem here is it's absent from the internal headers. So phew - this is a far less invasive change as it's basically 90% done already. I do wonder how we ever tested all that existing functionality though if it wasn't really needed for gcc? Or maybe it is in some specific cases? Anyway, this will probably get fixed sooner rather than later now I can see the problem more clearly. Thanks for reporting it. (Note there is some confusion here still to mull over... why are some internal functions defining themselves to be exported, when clearly they're internal? I suspect, but haven't yet checked, it's because some are called from static inline functions in the headers. It may be some of them need exports adding to the declarations, while others need exports removing from the definitions. Or it's the abomination that is hfile-plugins which uses internal parts of the library that aren't normally considered external. Argh! Solution here is just to bless them as officially external probably. Will let the main project lead make that call. :-) ) |
Thank you for figuring this out! |
Under mingw clang requires dllexport to be applied to both function declarations and function definitions. (Gcc is happy for the definition only to have the dllexport attribute.) Note this exports several "internal" functions, including some apparently unused anywhere (hts_json_*). Perhaps they were once used in htslib-plugins, but no more. I haven't taken the decision to remove these though, but it's worth considering for whenever we next do an ABI breaking change. Either that or stop pretending that their internal only when clearly they are not, and move their API to the external htslib/*.h files instead. These appear to be somewhat in Limbo right now. Fixes samtools#1433
Hi!
I was trying to build htslib on Windows (MSYS2, clang 14.0.0) using clang but it does not work at the moment.
Compilation produces several errors regarding dllexport:
`hfile.c:105:8: warning: redeclaration of 'hfile_init' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity)
^
./hfile_internal.h:98:8: note: previous declaration is here
hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity);
^
hfile.c:153:6: error: redeclaration of 'hfile_destroy' cannot add 'dllexport' attribute
void hfile_destroy(hFILE *fp)
^
./hfile_internal.h:110:6: note: previous declaration is here
void hfile_destroy(hFILE *fp);
^
hfile.c:203:5: error: redeclaration of 'hfile_set_blksize' cannot add 'dllexport' attribute
int hfile_set_blksize(hFILE *fp, size_t bufsiz) {
^
./hfile_internal.h:52:5: note: previous declaration is here
int hfile_set_blksize(hFILE *fp, size_t bufsiz);`
And so on. Any ideas how to fix this?
The text was updated successfully, but these errors were encountered: