2016-07-29 173 views
0

我想在Linux下爲win32交叉編譯一個小程序。它使用libarchive,它可以在我的fedora 23安裝中使用(通過dnf安裝),但我得到了很多鏈接器錯誤。mingw + libarchive:交叉編譯鏈接器錯誤

來源:https://github.com/panzi/save_the_zazus

編譯器/連接器輸出:

[email protected] save_the_zazus [master*]$ mkdir -p package/img 
[email protected] save_the_zazus [master*]$ touch package/img/atlas0.png package/img/atlas1.png package/img/atlas2.png 
[email protected] save_the_zazus [master*]$ make TARGET=win32 setup 
mkdir -p build/win32 build/src 
[email protected] save_the_zazus [master*]$ make TARGET=win32 
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c src/save_the_zazus.c -o build/win32/save_the_zazus.o 
xxd -i package/img/atlas0.png > build/src/package_img_atlas0_png.c 
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c build/src/package_img_atlas0_png.c -o build/win32/package_img_atlas0_png.o 
xxd -i package/img/atlas1.png > build/src/package_img_atlas1_png.c 
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c build/src/package_img_atlas1_png.c -o build/win32/package_img_atlas1_png.o 
xxd -i package/img/atlas2.png > build/src/package_img_atlas2_png.c 
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -Wall -Werror -Wextra -std=gnu11 -Ibuild/src -O2 -c build/src/package_img_atlas2_png.c -o build/win32/package_img_atlas2_png.o 
i686-w64-mingw32-gcc -m32 -DLIBARCHIVE_STATIC -static -larchive build/win32/save_the_zazus.o build/win32/package_img_atlas0_png.o build/win32/package_img_atlas1_png.o build/win32/package_img_atlas2_png.o -o build/win32/save_the_zazus.exe 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x301): undefined reference to `archive_read_new' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x31d): undefined reference to `archive_read_support_filter_all' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x3cd): undefined reference to `archive_entry_free' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x3df): undefined reference to `archive_read_free' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x3ef): undefined reference to `archive_write_free' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x426): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x462): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x4a1): undefined reference to `archive_read_support_format_all' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x538): undefined reference to `archive_read_open_filename' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x545): undefined reference to `archive_write_new' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x557): undefined reference to `archive_write_set_format_zip' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x56b): undefined reference to `archive_write_set_options' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x581): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x5c9): undefined reference to `archive_write_open_filename' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x5d9): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x61e): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x67a): undefined reference to `archive_entry_new2' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x6ba): undefined reference to `archive_read_next_header2' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x6d0): undefined reference to `archive_entry_pathname' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x727): undefined reference to `archive_entry_new2' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x73d): undefined reference to `archive_entry_copy_pathname' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x74b): undefined reference to `archive_entry_perm' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x75a): undefined reference to `archive_entry_set_perm' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x762): undefined reference to `archive_entry_filetype' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x771): undefined reference to `archive_entry_set_filetype' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x77f): undefined reference to `archive_entry_mode' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x78e): undefined reference to `archive_entry_set_mode' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7a5): undefined reference to `archive_entry_set_size' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7b3): undefined reference to `archive_entry_uid' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7c3): undefined reference to `archive_entry_set_uid' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7d1): undefined reference to `archive_entry_gid' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7e1): undefined reference to `archive_entry_set_gid' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x7ef): undefined reference to `archive_entry_mtime_nsec' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x803): undefined reference to `archive_entry_mtime' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x819): undefined reference to `archive_entry_set_mtime' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x82b): undefined reference to `archive_write_header' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x83b): undefined reference to `archive_entry_free' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x854): undefined reference to `archive_write_data' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x870): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x904): undefined reference to `archive_write_header' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x91a): undefined reference to `archive_entry_size' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x948): undefined reference to `archive_read_data' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x96c): undefined reference to `archive_write_data' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x988): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0x9dd): undefined reference to `archive_write_add_filter_none' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xa13): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xa47): undefined reference to `archive_entry_free' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xa8e): undefined reference to `archive_error_string' 
build/win32/save_the_zazus.o:save_the_zazus.c:(.text.startup+0xad6): undefined reference to `archive_error_string' 
collect2: error: ld returned 1 exit status 
Makefile:82: recipe for target 'build/win32/save_the_zazus.exe' failed 
make: *** [build/win32/save_the_zazus.exe] Error 1 

我剛剛寫了一個簡單的Makefile這個單一的源文件的程序。 png文件不在回購(還)中,因此如果您嘗試編譯,只需爲它們創建空文件。我試過動態和靜態鏈接(寧願靜態,所以我需要做的就是傳遞一個.exe文件)。對於這個輸出,我使用了-static -larchive,它並沒有抱怨任何缺少的庫,但是我得到了所有這些未定義的引用。

回答

1

-static -larchive添加到命令行的末尾,然後重試。鏈接器沒有讓庫鏈接。我發現它需要在命令行上保持最後。

+0

就是這樣。另外我不得不添加libarchive的所有依賴關係。 – panzi