1. 程式人生 > >ubuntu18.04,配以用wxWidgets編寫linux小程式

ubuntu18.04,配以用wxWidgets編寫linux小程式

需要安裝的東西主要是codebocks與wxWidgets。

1,codebocks可以在圖形介面中安裝codebocks-IDE.

這個的安裝比較簡單,如果電腦中已安裝好gnu工具它會自動找出。這時已可以寫簡單的小程式了。

2,要用wxWidgets,主要是開發圖開介面應用,所以還需要安裝編緝介面元素的plugin。這個只能用命令安裝。

sudo apt-get update

sudo apt-cache search codeblocks

sudo apt-get install codeblocks-contrib

還能看到其它的一些codeblocks模組,用到時再去安裝吧。

3,wxWidgets用原始碼安裝,下載wxWidgets-3.0.4.tar.bz2http://www.wxwidgets.org/.

解碼到一個目錄。

./configure --with-x11
make

sudo make install

設定其動態庫目錄:

cd /etc/ld.so.conf.d/
sudo touch wxWidgets.conf
sudo gedit wxWidgets.conf  #增加其內容為/usr/local/lib
重新載入動態庫配置資訊: 
sudo ldconfig

錯誤處理

1,pangoxft找不到的錯誤,解決方法一是/configure --with-x11 --disable-unicode ,這個方法中文顯示有問題。再就是apt升級一下它。

這裡升級時用個問題,在中國的伺服器,和美國的可升級的最新版本是有差別的。有用官方支中國區升級伺服器,不能成功安裝。這就要改/etc/apt/sources.list換成如下內容:這個檔案我是在github上找到的。

2,codeblock不需要配置就應當可以用的。但網上有說法有一wx的變數在要codeblock的setting中設為wxWidgets的原始碼目錄。但我配和這個變數,再刪去一樣好用。

4,ubuntu用的是x11而不是gtk但gtk對中文的支援好一些,如果出問題可以試一下把wxWidgets編譯成用gtk.

/configure --with-gtk --disable-shared

--disable-shared在新電腦上安裝時,會用重新一一把需要更新庫。

 gtk也是要安裝的,安裝時會遇到依賴錯誤,這個錯誤也是原因最新軟體包找不到引起的。當然也可能是別的問題。換用美國的伺服器試一下。這個需要開通ipv6才好用。

用gtk,x11基本的中文都沒什麼問題。用codeblock新建的工程試一下。把它符成改一部分為中文編譯沒問題,但新編譯的程式中文顯示可能還是有問題。這個可以用程式碼解決。

bool sample2App::OnInit()中加入如下程式碼。
       //用中文的關鍵
           if ( setlocale (LC_ALL,"") == NULL ) {
                //(void) fprintf (stderr, "%s: cannot set locale.n",
                //program_name );
                exit (1);
        }

X11與gtk的顯示視覺效果有一點差別。但影響不大。

/#sources.list using us server

# deb cdrom:[Ubuntu 18.04 LTS _Bionic Beaver_ - Release amd64 (20180426)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ bionic universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic universe
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://us.archive.ubuntu.com/ubuntu/ bionic multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://security.ubuntu.com/ubuntu bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse