範例
說明
Debian Package
執行
$ apt-cache search curl
顯示
curl - command line tool for transferring data with URL syntax
...略...
執行
$ apt-cache show curl
執行
$ apt-cache showsrc curl | grep '^Binary:'
顯示
Binary: curl, libcurl3, libcurl3-gnutls, libcurl3-nss, libcurl4-openssl-dev, libcurl4-gnutls-dev, libcurl4-nss-dev, libcurl3-dbg, libcurl4-doc
執行
$ apt-cache show libcurl4-openssl-dev
執行下面指令,安裝「libcurl4-openssl-dev」
$ sudo apt-get install libcurl4-openssl-dev
執行
$ dpkg -L libcurl4-openssl-dev | grep pc
顯示
/usr/lib/x86_64-linux-gnu/pkgconfig/libcurl.pc
執行
$ cat /usr/lib/x86_64-linux-gnu/pkgconfig/libcurl.pc
pkg-config
$ man pkg-config
執行
$ pkg-config --help
執行
$ pkg-config --list-all | grep libcurl
顯示
libcurl libcurl - Library to transfer files with ftp, http, etc.
執行
pkg-config --exists libcurl
echo $?
顯示
0
執行
$ pkg-config --debug libcurl
執行
$ pkg-config --cflags --libs libcurl
顯示
-lcurl
執行
$ pkg-config --debug --cflags --libs libcurl
執行
$ pkg-config --print-variables libcurl
顯示
exec_prefix
includedir
libdir
pcfiledir
prefix
supported_features
supported_protocols
執行
$ pkg-config --variable=libdir libcurl
顯示
/usr/lib/x86_64-linux-gnu
執行
for ITEM in $(pkg-config --print-variables libcurl); do
CMD="echo -n $ITEM="
$CMD
CMD="pkg-config --variable=$ITEM libcurl"
$CMD
done
顯示
exec_prefix=/usr
includedir=/usr/include
libdir=/usr/lib/x86_64-linux-gnu
pcfiledir=/usr/lib/x86_64-linux-gnu/pkgconfig
prefix=/usr
supported_features=SSL IPv6 UnixSockets libz AsynchDNS IDN GSS-API SPNEGO Kerberos NTLM NTLM_WB TLS-SRP
supported_protocols=DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTMP RTSP SMB SMBS SMTP SMTPS TELNET TFTP
產生專案資料夾
執行下面指令,產生專案資料夾。
$ mkdir -p demo-curl
切換到專案資料夾
$ cd demo-curl
下載範例程式碼
先到「libcurl - small example snippets」
找到「simple」這個範例,
可以找到下載的「連結」,
執行下面指令下載,並且更名為「main.c」。
$ wget -c https://raw.githubusercontent.com/curl/curl/master/docs/examples/simple.c -O main.c
build.sh
- https://developer.gnome.org/references
- https://developer.gnome.org/glib/stable/
- https://developer.gnome.org/glib/stable/glib-compiling.html
- https://www.freedesktop.org/wiki/Software/pkg-config/
- https://en.wikipedia.org/wiki/Pkg-config
- https://zh.wikipedia.org/zh-tw/Pkg-config
執行下面指令,產生「build.sh」
cat > build.sh << EOF
gcc -o app main.c \$(pkg-config --cflags --libs libcurl)
EOF
執行
$ cat build.sh
顯示
gcc -o app main.c $(pkg-config --cflags --libs libcurl)
執行
$ chmod u+x build.sh
執行
$ ./build.sh
執行「app」
執行編譯成功後的執行檔。
$ ./app
就會顯示「http://example.com」的網頁原始碼。
如同執行
$ curl http://example.com/
也可以執行下面指令,從「Firefox」看到「http://example.com」的網頁原始碼。
$ firefox view-source:http://example.com/