我正在尝试在Windows/msys2下编译wcslib
尽管该库在GNU/Linux和MacOS上编译时没有任何问题,但我仍然遇到msys2的问题:

wcs.h:1965:5: error: conflicting types for 'wcsset'
1965 | int wcsset(struct wcsprm *wcs);
| ^~~~~~
In file included from wcs.c:30:
C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:179:20: note: previous declaration of 'wcsset' was here
179 | wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~
wcs.c:2185:5: error: conflicting types for 'wcsset'
2185 | int wcsset(struct wcsprm *wcs)
| ^~~~~~
In file included from wcs.c:30:
C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:179:20: note: previous declaration of 'wcsset' was here
179 | wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~
make[3]: *** [GNUmakefile:135: libwcs-7.3.1.a(wcs.o)] Error 1
 
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsbth.c
In file included from wcsbth.l:121:
wcs.h:1965:5: error: conflicting types for 'wcsset'
1965 | int wcsset(struct wcsprm *wcs);
| ^~~~~~
In file included from wcsbth.c:231:
C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:179:20: note: previous declaration of 'wcsset' was here
179 | wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~
make[3]: *** [GNUmakefile:135: libwcs-7.3.1.a(wcsbth.o)] Error 1

gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcserr.c

gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsfix.c
In file included from wcsfix.c:38:
wcs.h:1965:5: error: conflicting types for 'wcsset'
1965 | int wcsset(struct wcsprm *wcs);
| ^~~~~~
In file included from wcsfix.c:30:
C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:179:20: note: previous declaration of 'wcsset' was here
179 | wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~
make[3]: *** [GNUmakefile:135: libwcs-7.3.1.a(wcsfix.o)] Error 1

gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcshdr.c
In file included from wcshdr.h:1276,
from wcshdr.c:36:
wcs.h:1965:5: error: conflicting types for 'wcsset'
1965 | int wcsset(struct wcsprm *wcs);
| ^~~~~~
In file included from wcshdr.c:31:
C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:179:20: note: previous declaration of 'wcsset' was here
179 | wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~
make[3]: *** [GNUmakefile:135: libwcs-7.3.1.a(wcshdr.o)] Error 1

gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcspih.c
In file included from wcspih.l:123:
wcs.h:1965:5: error: conflicting types for 'wcsset'
1965 | int wcsset(struct wcsprm *wcs);
| ^~~~~~
In file included from wcspih.c:231:
C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:179:20: note: previous declaration of 'wcsset' was here
179 | wchar_t *__cdecl wcsset(wchar_t *_Str,wchar_t _Val) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~
make[3]: *** [GNUmakefile:135: libwcs-7.3.1.a(wcspih.o)] Error 1

gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsprintf.c
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcstrig.c
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsulex.c
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsunits.c
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsutil.c
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c wcsutrn.c
make[3]: Target 'libwcs-7.3.1.a' not remade because of errors.
make[2]: *** [GNUmakefile:258: lib] Error 2
make[2]: Target 'build' not remade because of errors.
make[2]: Leaving directory '/home/siril/wcslib-7.3.1/C'
Mon 2020/12/07 09:23:14 +0100, executing on
make[2]: Entering directory '/home/siril/wcslib-7.3.1/utils'
cd .. && ./config.status
config.status: creating makedefs
config.status: creating wcslib.pc
config.status: creating wcsconfig.h
config.status: creating wcsconfig_f77.h
config.status: wcsconfig_f77.h is unchanged
config.status: creating wcsconfig_tests.h
config.status: wcsconfig_tests.h is unchanged
config.status: creating wcsconfig_utils.h
 
gcc -DHAVE_CONFIG_H -I.. -I../C -g -O2 -c -o fitshdr.o fitshdr.c
gcc -o fitshdr fitshdr.o -lm -pthread -lcurl -lm
make[2]: Leaving directory '/home/siril/wcslib-7.3.1/utils'
make[1]: Leaving directory '/home/siril/wcslib-7.3.1'
当然,更改lib函数的名称不是一种选择(至少不是我的选择)。有人知道摆脱它的好选择吗?例如,删除符号或其他方式的方法。

最佳答案

我看了看您的错误消息中提到的string.h文件。看起来您可以定义一个处理器宏NO_OLDNAMES来告诉头文件不要为wcsset生成原型(prototype)。
您仍然需要在链接时注意麻烦,但这可能就足够了。

关于c - 尝试使用msys2编译lib时发生类型冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/65179621/

10-12 22:47