当我使用minGW对windows进行交叉编译时,我会得到以下错误。如何为windows添加gcc库和交叉编译?我用的是x86_64-w64-mingw32-gcc,但它是用gcc编译的,没有任何问题。这个问题产生于gcc和minGW的不同搜索结果,很难在这里显示最小的可重现性结果。您可以找到源代码和cmake文件,下面的链接是< systems/-/tree/main/Assignment4%20MorseCodeDecoder >,如果我将编译器改为gcc,而不是将GNU上的所有工作内容混合起来,但是当我试图使用mingw编译一个exe时,编译器错误是由于gcc和minGW中的search.h有不同的定义而导致的。
./CMake clean-install
-- Cleaning files and directories
-- Deleting program: MorseCodeDecoder - done
-- Deleting build directory: build/ - done
-- Cleaning - done
-- Creating a new empty build directory:/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/build/ - done
-- The C compiler identification is GNU 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc - works
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/build
[ 20%] Building C object CMakeFiles/MORSE_LIB.dir/src/morse_lib/morse_code.c.o
In file included from /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/inc/main.h:29,
from /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/morse_code.c:1:
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/inc/read.h:10:62: warning: 'struct hsearch_data' declared inside parameter list will not be visible outside of this definition or declaration
10 | extern void read_morse_display_word(FILE *morse_file, struct hsearch_data *);
| ^~~~~~~~~~~~
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/morse_code.c: In function 'load_morse_code_into_hashtable':
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/morse_code.c:37:9: warning: implicit declaration of function 'hcreate_r' [-Wimplicit-function-declaration]
37 | hcreate_r(capacity, hashtable);
| ^~~~~~~~~
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/morse_code.c:43:32: warning: implicit declaration of function 'hsearch_r'; did you mean 'bsearch_s'? [-Wimplicit-function-declaration]
43 | int hsrc_res = hsearch_r(item, ENTER, &item_ptr, hashtable);
| ^~~~~~~~~
| bsearch_s
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/morse_code.c: In function 'clear_hashtable':
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/morse_code.c:51:9: warning: implicit declaration of function 'hdestroy_r' [-Wimplicit-function-declaration]
51 | hdestroy_r(hashtable);
| ^~~~~~~~~~
[ 40%] Building C object CMakeFiles/MORSE_LIB.dir/src/morse_lib/read.c.o
In file included from /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/inc/main.h:29,
from /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/read.c:1:
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/inc/read.h:10:62: warning: 'struct hsearch_data' declared inside parameter list will not be visible outside of this definition or declaration
10 | extern void read_morse_display_word(FILE *morse_file, struct hsearch_data *);
| ^~~~~~~~~~~~
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/read.c:24:6: error: conflicting types for 'read_morse_display_word'; have 'void(FILE *, struct hsearch_data *)' {aka 'void(struct _iobuf *, struct hsearch_data *)'}
24 | void read_morse_display_word(FILE *morse_file, struct hsearch_data *hashtable) {
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/inc/main.h:29,
from /home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/src/morse_lib/read.c:1:
/home/dirtyv/Codes/computer_systems/Assignment4 MorseCodeDecoder/inc/read.h:10:13: note: previous declaration of 'read_morse_display_word' with type 'void(FILE *, struct hsearch_data *)' {aka 'void(struct _iobuf *, struct hsearch_data *)'}
10 | extern void read_morse_display_word(FILE *morse_file, struct hsearch_data *);
| ^~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/MORSE_LIB.dir/build.make:90: CMakeFiles/MORSE_LIB.dir/src/morse_lib/read.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/MORSE_LIB.dir/all] Error 2
make: *** [Makefile:91: all] Error 2发布于 2022-10-10 15:09:18
hcreate_r和hsearch_data结构是对标准POSIX搜索函数的特定GNU扩展。
根据Linux manuap页面,在包含<search.h>以获得该功能之前,您必须定义_GNU_SOURCE。
不过,作为标准的扩展,它可能无法用于MinGW。
https://stackoverflow.com/questions/74016414
复制相似问题