BPG是一種數字圖像格式,比jpeg更有壓縮效果。 我想在OS X上編譯libbpg-0.9.610.10.5(14F1509)。我的Xcode版本是7.2.1(7C1002)。bpgview.c的主要功能不是由gcc編譯
$gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents
/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
我擁有所有必要的庫(見:github.com/mirrorer/libbpg)安裝。 當我運行使我有以下錯誤:
gcc -Os -Wall -MMD -fno-asynchronous-unwind-tables -fdata-sections -ffunction-sections -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -I. -DCONFIG_BPG_VERSION=\"0.9.6\" -g -I./x265/source -I./x265.out/8bit -c -o x265_glue.o x265_glue.c
g++ -g -Wl,-dead_strip -o bpgenc bpgenc.o x265_glue.o x265.out/8bit/libx265.a x265.out/10bit/libx265.a x265.out/12bit/libx265.a -lpng -ljpeg -lm -lpthread
gcc -Os -Wall -MMD -fno-asynchronous-unwind-tables -fdata-sections -ffunction-sections -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -I. -DCONFIG_BPG_VERSION=\"0.9.6\" -g -c -o bpgview.o bpgview.c
gcc -g -Wl,-dead_strip -o bpgview bpgview.o libbpg.a -lSDL_image -lSDL -lm -lpthread
ld: entry point (_main) undefined. for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bpgview] Error 1
我沒有檢查符號bpgview.o。不僅沒有int主要顯示,而且靜態無效幫助和靜態無效set_caption在bpgview.c。
$nm bpgview.o
U _IMG_Load
U _SDL_AddTimer
U _SDL_CreateRGBSurface
U _SDL_EnableKeyRepeat
U _SDL_FillRect
U _SDL_Flip
U _SDL_FreeSurface
U _SDL_GetVideoInfo
U _SDL_Init
U _SDL_LockSurface
U _SDL_MapRGB
U _SDL_PushEvent
U _SDL_RemoveTimer
U _SDL_SetVideoMode
U _SDL_UnlockSurface
U _SDL_UpperBlit
U _SDL_WM_SetCaption
U _SDL_WaitEvent
00000000000006f6 T _SDL_main
U ___snprintf_chk
U ___stack_chk_fail
U ___stack_chk_guard
U ___stderrp
U _bpg_decoder_close
U _bpg_decoder_decode
U _bpg_decoder_get_frame_duration
U _bpg_decoder_get_info
U _bpg_decoder_get_info_from_buf
U _bpg_decoder_get_line
U _bpg_decoder_open
U _bpg_decoder_start
0000000000000000 T _bpg_load
0000000000000404 T _center_image
0000000000000465 T _draw_image
U _exit
U _fclose
U _fopen
U _fprintf
U _fread
U _free
U _fseek
U _ftell
U _fwrite
U _getopt
000000000000021f T _load_image
U _malloc
0000000000000c64 t _open_window
U _optind
000000000000069a T _pan_image
U _printf
U _realloc
00000000000003c6 t _restart_frame_timer
0000000000000cbc t _timer_cb
完整的化妝輸出是pastebin.
我覺得很奇怪,但可能會有一些gcc的選項,我不知道這件事讓編譯器忽略功能。感謝您的時間。
也許'-Wl,-dead_strip'選項正在與您的代碼玩技巧。你可以嘗試刪除它嗎? – rodrigo
@rodrigo您的評論對此有幫助,鏈接器此次並未忽略'_SDL_main',並建議將其作爲主要使用。我試着用'-e _SDL_main'選項編譯它。即使幫助功能存在於可執行文件中。編譯器在那裏做了什麼以及鏈接器在哪裏獲得了幫助函數,這仍然是一個謎。謝謝,但作爲問題的*機制仍未解決,我現在離開這個問題一段時間了。 – H21
'-e'選項可能會讓事情變得更糟。入口點有非常明確的要求,通常在C庫內部深處,而不是在用戶'main'函數中。你有沒有試過編譯_hello-world_例子? – rodrigo