GiNaC在windows下的編譯—–MSYS下如何使用pkg-config?

來源:互聯網
上載者:User

 

想在windows下使用GiNaC ,無奈官網給的win32版本非常舊,GiNaC version 1.4.4, CLN version 1.2.2, and GMP version 4.2.4  ,   現在GiNaC都1.5.7,cln 1.3.1,GMP5.0.1 了。

 

那就只好自己動手了,先下載,TDM/MinGW,然後安裝MSYS,指定好剛才安裝的MinGW的路徑(即掛載)。

 

然後下載了最新的 GMP,5.0.1,編譯安裝:

 ./configure --prefix=/GiNaC --enable-cxx  --disable-static --enable-shared

make

make install

 

 

由於GiNaC的安裝要依賴於cln,而它的configure裡面沒有with-cln選項,需要pkg-config來自動識別,而cln也支援pkg-config,所以我們應該把pkg-config的安裝放在cln的安裝步驟之前。 

 

然而MSYS下的pkg-config的編譯可不是一件容易的事,性急的我直接使用別人編譯好的二進位版本,官網上沒有給二進位版本,

於是網上搜尋,找到了GNOME網站上給出的編譯好的windows二進位版本

http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip

 

解壓縮到MSYS的1.0目錄下,即相當於把pkg-config.exe放在了MSYS的 /bin 目錄下,運行發現還缺少libglib-2.0-0.dll檔案,呵呵,這個我經常遇到,以前安裝過Gtk+,於是照例,搜尋別人已經編譯好的libglib-2.0-0.dll檔案,湊巧,CSDN上有人也遇到了同樣的問題,不過,我用的版本跟博主的不一樣:

http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.24/glib_2.24.1-1_win32.zip

解壓,直接提取libglib-2.0-0.dll檔案,放在MSYS的  /bin目錄下

試一下命令,pkg-config.exe --help,發現正常~~,然後設定 PKG_CONFIG_PATH,好讓pkg-config找到pc檔案。根據我軟體安裝的位置,我安裝完的軟體的pc檔案應該在/GiNaC/lib/pkgconfig裡面。所以,開啟MSYS裡面的/etc/profile檔案,在末尾添加命令

export PKG_CONFIG_PATH=/mingw/lib/pkgconfig:/GiNaC/lib/pkgconfig

export PATH=/GiNaC/bin:$PATH

 

 附註:/GiNaC/bin目錄將會存有GMP,cln 的dll檔案,添加到PATH裡,可以省去拷貝到MSYS的系統/bin目錄的操作了。

 

 

接下來 就可以放心編譯cln了 , 下載cln1.3.1,編譯:

 ./configure --prefix=/GiNaC --with-gmp=/GiNaC --disable-static --enable-shared

make

make install

 

 

 

再下面,就是我的終極目標,GiNaC的編譯了,期待已久了啊, 

 

 

 ./configure --prefix=/GiNaC --disable-static --enable-shared

make

make install

 

 

檢測一下pkg-config能識別多少軟體:

$ pkg-config.exe --list-all
ginac GiNaC - C++ library for symbolic calculations
gsl   GSL - GNU Scientific Library
cln   cln - Class Library for Numbers
sdl   sdl - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low
level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.

 

OK,正常!!!

 

下面,就是最驚心動魄的事了,編譯例子:

 

clntest.cpp:

#include <iostream><br />#include <cln/cln.h><br />using namespace std;<br />using namespace cln;<br />int main(int argc, char *argv[]){</p><p> cl_F e = "0.271828182845904523536028747135266249775724709369996e+1_40";<br /> cout << "e = " << e << endl;<br /> cout << "e^2 = " << e*e << endl;<br /> return 0;<br />}<br />

 

gsltest.C  :

 

 

 

#include <stdio.h><br />#include <gsl/gsl_math.h><br />#include <gsl/gsl_sf_bessel.h><br />#include <gsl/gsl_poly.h><br />int main (void){<br />double x=5,roots[3]; gsl_complex z[3];<br />printf ("%.16f/t%.16f/nis 8 an odd number? %d/n", M_PI, M_EULER,GSL_IS_ODD(8));<br />printf("J0(%g) = %.16f/n",x,gsl_sf_bessel_J0(x));</p><p>gsl_poly_solve_cubic(-5,7,-2,roots,roots+1,roots+2);<br />printf("/nx^3-5x^2+7x-2=0 has roots:/n");<br />printf("%.16f/t%.16f/t%.16f/n",roots[0],roots[1],roots[2]);<br />gsl_poly_complex_solve_cubic(0,1,-2,z,z+1,z+2);<br />printf("/nx^3+x-2=0 has roots:/n");<br />printf("%+.16f%+.16f I/n%+.16f%+.16f I/n%+.16f%+.16f I/n", GSL_REAL(z[0]), GSL_IMAG(z[0]), GSL_REAL(z[1]), GSL_IMAG(z[1]), GSL_REAL(z[2]), GSL_IMAG(z[2]));<br />// getch();<br />return 0;<br />}

 

 

GiNaC例子:

 

 

#include <iostream><br />#include <ginac/ginac.h></p><p>using namespace std;<br />using namespace GiNaC;</p><p>int main(int argc, char **argv)<br /> {<br /> symbol a("a"), b("b"), c("c");<br /> symbol x("x"), y("y");</p><p> ex f = x*sin(3*a*x) - exp(-b*y) + c*tanh(c*x*y*y);</p><p> ex dfx = f.diff(x);<br /> ex dfy = f.diff(y);</p><p> cout << "f = " << f << endl;<br /> cout << "df/dx = " << dfx << endl;<br /> cout << "df/dy = " << dfy << endl;<br /> }

 

編譯cln例子,只需 :

g++ clntest.cpp `pkg-config.exe --libs --cflags cln` -o clntest

 

 

 

貼一張圖紀念一下:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.