2014-01-12 45 views
1

我想鏈接我的程序與libjpeg。'未定義的引用'與g ++編譯時

臂的Mandriva-Linux的gnueabi-G ++ v4l2grab2.cpp -o v4l2grab -Wall -llib -ljpeg

錯誤:

v4l2grab2.cpp:(.text+0xa28): undefined reference to `jpeg_std_error(jpeg_error_mgr*)' 
v4l2grab2.cpp:(.text+0xa44): undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int, unsigned int)' 
v4l2grab2.cpp:(.text+0xa54): undefined reference to `jpeg_stdio_dest(jpeg_compress_struct*, _IO_FILE*)' 
v4l2grab2.cpp:(.text+0xa88): undefined reference to `jpeg_set_defaults(jpeg_compress_struct*)' 
v4l2grab2.cpp:(.text+0xaa4): undefined reference to `jpeg_set_quality(jpeg_compress_struct*, int, int)' 
v4l2grab2.cpp:(.text+0xab4): undefined reference to `jpeg_start_compress(jpeg_compress_struct*, int)' 
v4l2grab2.cpp:(.text+0xaf0): undefined reference to `jpeg_write_scanlines(jpeg_compress_struct*, unsigned char**, unsigned int)' 
v4l2grab2.cpp:(.text+0xb1c): undefined reference to `jpeg_finish_compress(jpeg_compress_struct*)' 
v4l2grab2.cpp:(.text+0xb28): undefined reference to `jpeg_destroy_compress(jpeg_compress_struct*)' 

但是,當i中的文件重命名爲的* .c並嘗試編譯它與arm-mandriva-linux-gnueabi-gcc(而不是g ++)一切作品

我真的需要在C++代碼中使用它。 如何使用g ++編譯此代碼?

+0

聽起來就像是的libjpeg misbuilt。 –

+1

C風格的函數聲明需要放在'extern「C」塊中 –

回答

5

看來你是包括一個沒有C++支持的C頭。嘗試包括從extern "C"塊中的相關標題:

extern "C" { 
#include <jpeglib.h> 
} 

(因爲你沒有發佈任何代碼,我不知道這頭,你嘗試包括,只是猜測<jpeglib.h>)。

如果你需要包括<jpeglib.h>從頭部也應該是可行的包括從C,你會與C++測試包起來:

#ifdef __cplusplus 
extern "C" { 
#endif 
#include <jpeglib.h> 
#ifdef __cplusplus 
} 
#endif 
+0

它的工作原理! 非常感謝! – vitperov