方法源自 https://www.2cto.com/os/201304/201677.html glib安裝
http://www.cnblogs.com/pcat/p/5520317.html gstreamer安裝
一 源碼安裝glib
glib庫是GTK+和GNOME工程的基礎底層核心程序庫,是一個綜合用途的實用的輕量級的C程序庫,它提供C語言的常用的數據結構的定義、相關的處理函數,有趣而實用的宏,可移植的封裝和一些運行時機能,如事件循環、線程、動態調用、對象系統等的API。它能夠在類UNIX的操作系統平臺(如LINUX、HP-UNIX等)、WINDOWS、OS2和BeOS等操作系統臺上運行。
本文將介紹在linux下源碼安裝glib庫的過程,這過程很麻煩,一點都不輕鬆,故記錄下。
------
1、安裝glib
http://ftp.acc.umu.se/pub/GNOME/sources/glib/
我下載了個glib-2.48.1.tar.xz,如果是.tar.xz格式用tar -xvf解壓,如果是.tar.gz格式用tar -zxvf解壓
解壓後進入目錄後,三部曲:
./configure make make install
看起來是簡單,但第一步./configure問題多多,諸多問題請看下面各種解決法子。
2、zlib問題
報錯如下:
configure: error: *** Working zlib library and headers not found ***
自glib-2.23開始就需要zlib,zlib是提供數據壓縮用的函式庫。
http://www.zlib.net/ (下載地址在網頁的中間部分)
我下載了個zlib-1.2.8.tar.gz,解壓、進目錄,三部曲:
./configure make make install
3、libffi問題
報錯如下:
No package 'libffi' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables LIBFFI_CFLAGS and LIBFFI_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.
"FFI" 的全名是Foreign Function Interface,通常指的是允許以一種語言編寫的代碼調用另一種語言的代碼。而libffi庫只提供了最底層的、與架構相關的、完整的"FFI",在它之上必須有一層來負責管理兩種語言之間參數的格式轉換。
我下載了libffi-3.2.1.tar.gz,解壓、進目錄,三部曲:
./configure make make install
4、libmount 問題
報錯如下:
configure: error: *** Could not find libmount
sudo apt install libmount-dev
5、pkg-config問題
報錯如下:
configure: error: The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config.
pkg-config能根據軟件安裝時軟件的.pc配置文件路徑找到相應的頭文件路徑和庫文件路徑。
https://www.freedesktop.org/wiki/Software/pkg-config/
我下載了pkg-config-0.29.1.tar.gz,解壓、進目錄,三部曲:
./configure make make install
如果第一步遇到如下錯誤:
configure: error: Either a previously installed pkg-config or "glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure to use the bundled copy.
只需要:
./configure --with-internal-glib
6、pcre問題
報錯如下:
configure: error: Package requirements (libpcre >= 8.13) were not met: No package 'libpcre' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables PCRE_CFLAGS and PCRE_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.
PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括perl兼容的正則表達式庫。這些在執行正規表達式模式匹配時用與Perl 5同樣的語法和語義是很有用的,也可以來解決C語言中使用正則表達式的問題。
https://sourceforge.net/projects/pcre/files/pcre/
我下載了pcre-8.38.tar.gz,解壓、進目錄,改動的三部曲:
./configure --enable-utf8 --enable-unicode-properties make make install
如果第一步只是./configure,到時候安裝glib會繼續報錯:
checking for Unicode support in PCRE... no configure: error: *** The system-supplied PCRE does not support Unicode properties or UTF-8.
所以第一步是爲了解決Unicode、UTF-8的支持,僅限於pcre7.9以上版本
*安裝pcre如果報錯如下:
configure: error: You need a C++ compiler for C++ support
那是你所用的linux沒支持c++編譯,只需要:
apt-get install build-essential
**當安裝好pcre後,輸入pcretest -C來打印pcre的安裝情況,一般輸出如下:
PCRE version 8.38 2015-11-23
Compiled with
8-bit support
UTF-8 support
Unicode properties support
No just-in-time compiler support
Newline sequence is LF
\R matches all Unicode newlines
Internal link size = 2
POSIX malloc threshold = 10
Parentheses nest limit = 250
Default match limit = 10000000
Default recursion depth limit = 10000000
Match recursion uses stack
而如果報錯爲:
pcretest: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory pcretest: error while loading shared libraries: libpcreposix.so.0: cannot open shared object file: No such file or directory
這種情況好像大多數linux都會發生,只需要自己建立一個軟鏈接即可:
ln -s /usr/local/lib/libpcre.so.1 /lib ln -s /usr/local/lib/libpcreposix.so.0 /lib
(如果之後還沒用,可以考慮把/lib換/lib64)
6、glib使用方法
*如果都按照上面所列舉的種種問題仔細折騰了後還有問題的話,請留言給我。(本人在Kali2、Kali Rolling、Ubuntu等都測試過了)
現在寫一個簡單的c語言代碼,命名爲hello.c
#include <glib.h> int main(int argc, char** argv){ GList* list=NULL; list=g_list_append(list,"Hello world!"); list=g_list_append(list,"made by pcat"); list=g_list_append(list,"http://pcat.cnblogs.com"); printf("The first item is %s\n",g_list_first(list)->data); return 0; }
編譯如下:
gcc $(pkg-config --cflags --libs glib-2.0) hello.c -o hello ./hello
如果在一些linux上報錯:
undefined reference to `g_list_append' undefined reference to `g_list_first'
那是因爲有些gcc存在編譯參數的順序問題,$(pkg-config --cflags --libs glib-2.0)放在源文件的前面,而當編譯器在源文件中遇到不能解析的函數時,在源文件之後的選項中尋找相關的信息,那麼就出現了編譯錯誤,也就是無法找到相關的函數定義。
所以只需要:
gcc hello.c -o hello $(pkg-config --cflags --libs glib-2.0)
二、ubuntu16.04安裝gstreamer的的步驟
在安裝gsteamer的過程中可能會遇到以下錯誤:
1. configure: error: Could not find bison
$sudo apt-get install bison
2. configure: error: Could not find flex
$sudo apt-get install flex
3. configure: error: *** Working zlib libraryand headers not found***
$sudo apt-get install zlib1g
1、 首先下載所需的安裝包
https://gstreamer.freedesktop.org/src/
gstreamer-1.8.0.tar.xz
gst-plugins-base-1.8.0.tar.xz
gst-plugins-good-1.8.0.tar.xz
gst-plugins-ugly-1.8.0.tar.xz
gst-libav-1.8.0.tar.xz
2、 下載所需的庫
libxml2-2.7.8.tar.gz //連接ftp://xmlsoft.org/libxml2/
glib-2.55.1.tar.gz //https://ftp.gnome.org/pub/GNOME/sources/glib/
3、 安裝libxzml2
sudo tar –xzf libxml2-2.7.8.tar.gz
cd libxml2-2.7.8/
sudo ./configure
sudo make
sudo make install
4、 安裝glib-2.55.1
sudo xz –d glib-2.55.1.tar.gz
sudo tar –xzf glib-2.55.1.tar
cd glib-2.55.1/
sudo ./configure
sudo make
sudo make install
5、 安裝gstreamer
sudo xz –d gstreamer-1.8.0.tar.gz
sudo tar –xvf gstreamer-1.8.0.tar
cd / gstreamer-1.8.0/
sudo ./configure
sudo make
sudo make install
6、 安裝gst-plugins-base-1.8.0.tar.xz
sudo xz –d gst-plugins-base-1.8.0.tar.xz
sudo tar –xvf gst-plugins-base-1.8.0.tar
cd gst-plugins-base-1.8.0/
sudo ./configure
sudo make
sudo make install
7、 安裝 gst-plugins-good-1.8.0.tar.xz
sudo xz –d gst-plugins-good-1.8.0.tar.gz
sudo tar –xvf gst-plugins-good-1.8.0.tar
cd gst-plugins-good-1.8.0/
sudo ./configure
sudo make
sudo make install
此時,使用命令
gst-launch -vm audiotestsrc ! audioconvert ! audioresample ! osssink
測試能在揚聲器裏聽到蜂鳴音
8、安裝gst-plugins-ugly-1.8.0,播放mp3需要的插件mad
sudo xz –d gst-plugins-ugly-1.8.0.tar.gz
sudo tar –xvf gst-plugins-ugly-1.8.0.tar
cd gst-plugins-ugly-1.8.0/
sudo ./configure
sudo make
sudo make install
裝完這個軟件之後,使用以下命令播放music.mp3
gst-launch filesrc location=music.mp3 ! mad ! audioconvert ! audioresample ! osssink
測試是否安裝成功,正常的話會播放歌曲,不過本人測試時,播放的聲音比較破。
9、安裝gst-libav-1.8.0.tar.xz
在執行configure是可能會出現 ffmpeg yasm not found, use --disable-yasm for
a crippled build
編譯FFMPEG時,出現了 ffmpeg yasm not found, use --disable-yasm for a crippled build,是因爲 FFMPEG爲了提高編譯速度,使用了彙編指令,如果系統中沒有yasm指令的話,就會出現上述的問題。
解決辦法是:
A 如果是Windows系統, 從網上下載一個 yasm.exe 並安裝在mingw/bin下面,重新編譯,就不會出現該錯誤了;
B 如果是Linux系統,則更簡單,直接在終端輸入 sudo apt-get install yasm ,安裝好後,重新編譯就 OK了。
sudo xz –d gst-libav-1.8.0.tar.xz
sudo tar –xvf gst-libav-1.8.0.tar
cd gst-libav-1.8.0/
sudo ./configure
sudo make
sudo make install
可能還需要設置具體的參數。
安裝後相關文件的默認路徑或在安裝時配置的路徑:
配置環境變量
export LD_LIBRARY_PATH=/usr/local/lib
export GST_PLUGIN_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu/gstreamer-1.0
三、ubuntu沒有聲音
方法:
1.打開控制面板中聲音設備屬性,
2
打開錄音選項卡,並鼠標右鍵顯示所有禁用設備,其中有一個設備出現了:立體聲混音,
3 點擊啓用,並設置爲默認設備,就好了!
4
在VMware裏面的是聲卡設定默認主板選項
5 重啓虛擬機。