-l参数就是用来指定程序要链接的库,-l参数紧接着就是库名,那么库名跟真正的库文件名有什么关系呢?就拿数学库来说,他的库名是m,他的库文件名是libm.so,很容易看出,把库文件名的头lib和尾.so去掉就是库名了
好了现在我们知道怎么得到库名,当我们自已要用到一个第三方提供的库名字libtest.so,那么我们只要把libtest.so拷贝到/usr/lib里,编译时加上-ltest参数,我们就能用上libtest.so库了(当然要用libtest.so库里的函数,我们还需要与libtest.so配套的头文件)
放在/lib和/usr/lib和/usr/local/lib里的库直接用-l参数就能链接了,但如果库文件没放在这三个目录里,而是放在其他目录里,这时我们只用-l参数的话,链接还是会出错,出错信息大概是:“/usr/bin/ld: cannot find -lxxx”,也就是链接程序ld在那3个目录里找不到libxxx.so,这时另外一个参数-L就派上用场了,比如常用的X11的库,它在/usr/X11R6/lib目录下,我们编译时就要用-L/usr/X11R6/lib -lX11参数,-L参数跟着的是库文件所在的目录名。再比如我们把libtest.so放在/aaa/bbb/ccc目录下,那链接参数就是-L/aaa/bbb/ccc -ltest
另外,大部分libxxxx.so只是一个链接,以RH9为例,比如libm.so它链接到/lib/libm.so.x,/lib/libm.so.6又链接到/lib/libm-2.3.2.so,
如果没有这样的链接,还是会出错,因为ld只会找libxxxx.so,所以如果你要用到xxxx库,而只有libxxxx.so.x或者libxxxx-x.x.x.so,做一个链接就可以了ln -s libxxxx-x.x.x.so libxxxx.so
手工来写链接参数总是很麻烦的,还好很多库开发包提供了生成链接参数的程序,名字一般叫xxxx-config,一般放在/usr/bin目录下,比如
gtk1.2的链接参数生成程序是gtk-config,执行gtk-config --libs就能得到以下输出"-L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic
-lgmodule -lglib -ldl -lXi -lXext -lX11 -lm",这就是编译一个gtk1.2程序所需的gtk链接参数,xxx-config除了--libs参数外还有一个参数是--cflags用来生成头文件包含目录的,也就是-I参数,在下面我们将会讲到。你可以试试执行gtk-config --libs --cflags,看看输出结果
现在的问题就是怎样用这些输出结果了,最笨的方法就是复制粘贴或者照抄,聪明的办法是在编译命令行里加入这个`xxxx-config --libs --cflags`,比如编译一个gtk程序:gcc gtktest.c `gtk-config --libs --cflags`这样就差不多了。注意`不是单引号,而是1键左边那个键。
5、-include和-I参数
-include用来包含头文件,但一般情况下包含头文件都在源码里用#include xxxxxx实现,-include参数很少用。-I参数是用来指定头文件目录,/usr/include目录一般是不用指定的,gcc知道去那里找,但是如果头文件不在/usr/include里我们就要用-I参数指定了,比如头文件放在/myinclude目录里,那编译命令行就要加上-I/myinclude参数了,如果不加你会得到一个"xxxx.h: No such file or directory"的错误。-I参数可以用相对路径,比如头文件在当前目录,可以用-I.来指定。
好记性不如烂博客
2010年11月2日星期二
Ubuntu下编译OpenMesh
首先介绍以下OpenMesh,这是一个开源的跨平台Mesh数据结构的类库,由RWTH开发。(别告诉我你不知道什么叫Mesh),由于大量使用C++模板技术,使得OpenMesh具有很高的性能以及良好的扩展性,具体的介绍参见OpenMesh的主页:http://www.openmesh.org/
现在来说在Ubuntu下如何编译OpenMesh:第一步,下载OpenMesh的源代码,在主页上Download标签可以找到下载的地址,我下载的是最新的OpenMesh 2.0-RC5版本。(如果想要最新的开发版本,可以使用SVN下载,网页上提供了SVN服务器的地址)下载后解压到某个文件夹,比如/home/jixu/OpenMesh/OpenMesh-2.0-RC5/。
第二步,其实OpenMesh本身并不依赖于其他的库,可是要编译他的例子程序就需要其他的几个库:QT,OpenGL,GLUT, GLEW。Ubuntu安装这几个库非常简单,只需要使用软件包管理就很容易的安装了。这几个软件包分别是:libgl1-mesa-dev , libglu1-mesa-dev , freeglut3-dev , qt4-dev-tools , libglew1.5-dev 。使用apt-get安装即可。(这些库对应的dbg我也安装了,不知道以后有没有用)。
第三步,使用CMake安装,首先要确保你的机器安装了cmake。(如果没有安装,就apt-get install cmake )新建一个目录(比如我的是usr/leo/OpenMesh),进入这个目录执行 cmake <openmesh解压的目录> (我的是cmake /home/leo/OpenMesh-2.0-RC5/)。这时cmake开始生成所需的makefile,可是一秒钟之后屏幕显示配置没完成,我看了看error的信息,大概意思说在配置GLUT时找不到两个关键的变量,于是我就看看是不是glut没有安装成功,可是写了个opengl的测试程序证明glut是安装了的,然后google了半天也没啥效果,在cmake的maillist中找到了个.cmake文件(设置那两个变量的)加到cmake子目录下,错误依旧。。。由于不懂CMake的机制所以在那些.cmake文件中看来看去,(这里省略两千字),最后发现ms不是什么GLUT的问题,是有另外两个库没有安装的原因,于是安装libxi-dev ,libxmu-dev ,再执行cmake,成功!最后执行make编译,过了3分钟左右吧,新建目录下的Build子目录就是编译好的库了。赶紧运行了Build/bin下的QtViewer,可以显示我的模型(例如.off的模型文件),很帅!
最后说一下,如果要是自己写程序调用OpenMesh的话,需要指定头文件路径和共享库的路径(我是使用共享库的,静态库整个库都在一起,很大不推荐),将/home/leo/OpenMesh-2.0-RC5/src/OpenMesh拷贝到/usr/local/include下,将/home/leo/OpenMesh/Build/lib/OpenMesh目录下的libOpenMeshCore.so.2.0和libOpenMeshCore.so拷贝到了/usr/local/lib目录下(因为gcc在链接时会自动找这个目录),最后执行一下sudo ldconfig -v 更新一下。这时就可以自己编译了,比如,进入OpenMesh源代码的教程目录(我的是/home/leo/OpenMesh/OpenMesh-2.0-RC5/src/OpenMesh/Example/),然后进入Tutorial01子目录,执行g++ -l OpenMeshCore cube.cc ,如果没有错误会生成a.out,接着执行a.out ,生成了output.off,说明我们编译成功了。
现在来说在Ubuntu下如何编译OpenMesh:第一步,下载OpenMesh的源代码,在主页上Download标签可以找到下载的地址,我下载的是最新的OpenMesh 2.0-RC5版本。(如果想要最新的开发版本,可以使用SVN下载,网页上提供了SVN服务器的地址)下载后解压到某个文件夹,比如/home/jixu/OpenMesh/OpenMesh-2.0-RC5/。
第二步,其实OpenMesh本身并不依赖于其他的库,可是要编译他的例子程序就需要其他的几个库:QT,OpenGL,GLUT, GLEW。Ubuntu安装这几个库非常简单,只需要使用软件包管理就很容易的安装了。这几个软件包分别是:libgl1-mesa-dev , libglu1-mesa-dev , freeglut3-dev , qt4-dev-tools , libglew1.5-dev 。使用apt-get安装即可。(这些库对应的dbg我也安装了,不知道以后有没有用)。
第三步,使用CMake安装,首先要确保你的机器安装了cmake。(如果没有安装,就apt-get install cmake )新建一个目录(比如我的是usr/leo/OpenMesh),进入这个目录执行 cmake <openmesh解压的目录> (我的是cmake /home/leo/OpenMesh-2.0-RC5/)。这时cmake开始生成所需的makefile,可是一秒钟之后屏幕显示配置没完成,我看了看error的信息,大概意思说在配置GLUT时找不到两个关键的变量,于是我就看看是不是glut没有安装成功,可是写了个opengl的测试程序证明glut是安装了的,然后google了半天也没啥效果,在cmake的maillist中找到了个.cmake文件(设置那两个变量的)加到cmake子目录下,错误依旧。。。由于不懂CMake的机制所以在那些.cmake文件中看来看去,(这里省略两千字),最后发现ms不是什么GLUT的问题,是有另外两个库没有安装的原因,于是安装libxi-dev ,libxmu-dev ,再执行cmake,成功!最后执行make编译,过了3分钟左右吧,新建目录下的Build子目录就是编译好的库了。赶紧运行了Build/bin下的QtViewer,可以显示我的模型(例如.off的模型文件),很帅!
最后说一下,如果要是自己写程序调用OpenMesh的话,需要指定头文件路径和共享库的路径(我是使用共享库的,静态库整个库都在一起,很大不推荐),将/home/leo/OpenMesh-2.0-RC5/src/OpenMesh拷贝到/usr/local/include下,将/home/leo/OpenMesh/Build/lib/OpenMesh目录下的libOpenMeshCore.so.2.0和libOpenMeshCore.so拷贝到了/usr/local/lib目录下(因为gcc在链接时会自动找这个目录),最后执行一下sudo ldconfig -v 更新一下。这时就可以自己编译了,比如,进入OpenMesh源代码的教程目录(我的是/home/leo/OpenMesh/OpenMesh-2.0-RC5/src/OpenMesh/Example/),然后进入Tutorial01子目录,执行g++ -l OpenMeshCore cube.cc ,如果没有错误会生成a.out,接着执行a.out ,生成了output.off,说明我们编译成功了。
2010年11月1日星期一
翻墙脚本
#!/bin/sh
sudo cp /etc/resolv.conf.backup /etc/resolv.conf
sudo /etc/init.d/networking restart
python ~/localproxy-2.0.0/proxy.py
sudo cp /etc/resolv.conf.backup /etc/resolv.conf
sudo /etc/init.d/networking restart
python ~/localproxy-2.0.0/proxy.py
2010年10月31日星期日
To install CGAL 3.6 on Visual Studio 2010, Win 7
1. install cmake (using latest 2.8.1)
1.1. There is remark that you need to change CMakeVS10FindMake.cmake
where is that ?
If using Binary distribution, it will be $(CMAKE_DIR)\share\cmake-2.8\Modules
If you like to complie by yourself, it will be &(CMAKE_DIR)\Modules
1.2 To complie by yourself, you need to change the file first, and download cmake Binary to make project(it sounds wired but please see Installing CMake).
1.3 After making project, you can use Visual Studio 2010 to make binary
Sample open .sln file and run release
2. Configure your "system envirnoment", add $(CMAKE_DIR)\bin in "path" for you can execute cmake anytime.
For Binary ditribution: $(CMAKE_DIR)\bin (example)
For src compiled: $(CMAKE_DIR)\bin\$(OUTDIR)
3. Install Boost (latest 1.43.0)
because boostpro do not support vs 2010, you have to compile by yourself.
3.1 download Boost http://www.boost.org/users/download/
3.2 for build Boost "Boost Jam" http://sourceforge.net/projects/boost/files/boost-jam/3.1.18/
3.3 copy bjam.exe to $(boost_DIR)
3.4 run bjam --build-dir="d:\build-boost" --build-type=complete msvc
build-dir: is the dir to work
build-type=complete means to build all
remark: I have try skip this, and it works.
it takes about 1 hr to build complete, and about 20 min to do default
after building, file will in $(BOOST_DIR)/stage/lib
3.5 add "system environment" in "path" add "$(BOOST_DIR)"
this for CGAL know where is BOOST
4. Install Exact Arithmetic
CGAL support GMP+MPFR, MPFI, LEDA
This time the program I use only needs GMP + MPFR
CGAL said they provide precompile GMP + MPFR, but they do not support 2010 at this time.
Everything have do by yourself.
GMP is not support visual Studio. (may they don't like M$)
Luckly, there is someone porting to visual studio call MPIR
4.1 install MPIR
download from http://www.mpir.org/#release
they even have visual studio 2010 version very cool.
Sample unzip and open .sln
run release.
copy all ".h" file in the $(outdir) to $(CGAL)/auxiliary/gmp/include
copy all .lib and ".dll" file in the $(outdir) to $(CGAL)/auxiliary/gmp/lib
4.2 install MPFR
again, MPFR does not support VS
you can find someone provide vs 2008 project file here http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php
just download here
4.2.1 download MPFR http://www.mpfr.org/
because the project support 2.4.1 only, I use version 2.4.1
4.2.2 copy vs 2009 project file to $(MPFR_DIR)
4.2.3 copy all MPIR in $(OUT_DIR) files to $(MPFR_DIR)/../mpir
4.2.4 run $(MPFR_DIR)/build.vc9/lib_mpfr.sln
vs2010 will convert for you. it takes about 2 mins
change the lib_mpfr property... / configuration Property / Librarian /
additional Dependencies
../../mpir/....... -> ../../mpir/mpir.lib (or the path you put mpir.lib)
and run release..
4.2.5 run $(MPFR_DIR)/build.vc9/dll_mpfr.sln
change the dll_mpfr property... / configuration Property / Linker /
additional Dependencies
../../mpir/....... -> ../../mpir/mpir.lib (or the path you put mpir.lib)
and run release..
4.2.6 copy all ".h" file in the $(outdir) to $(CGAL)/auxiliary/gmp/include
copy all .lib and ".dll" file in the $(outdir) to $(CGAL)/auxiliary/gmp/lib
copy $(mpfr)/mpfr.h to $(CGAL)/auxiliary/gmp/include
5. Visualization
5.1 install Qt
Qt is going to support windows 7 and visual Studio 2010 at version Qt 4.7
so I download Qt 4.7 beta filename: qt-everywhere-opensource-src-4.7.0-beta1
5.2 unzip and set environments
environments set PATH += $(QT_DIR)/bin
set LIB += C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
set Include += C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include
5.3 fix some error
in $(QTDIR)\src\3rdparty\webkit\JavaScriptCore\runtime
at line 171
transitionTable()->add(key, Transition(structure, 0));
change to
transitionTable()->add(key, Transition(structure, nullptr));
at line 178
transitionTable()->add(key, Transition(0, structure));
change to
transitionTable()->add(key, Transition(nullptr, structure));
5.4 run configure at $(QT_DIR) using Visual Studio Command Prompt
because Qt didn't support vs2010, just use vs2008 setting
configure.exe -platform win32-msvc2008 -fast
on internet there is simple run command (less warning and no error): http://stackoverflow.com/questions/1644172/building-qt-4-5-with-visual-c-2010
configure.exe -platform win32-msvc2008 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
you can choose any one is ok.
5.5 nmake
it takes long time if there is no error.
5.6 you finish installing QT
6. Miscellaneous
I didn't use this, so Skip this part
7. install CGAL
7.1 download CGAL http://www.cgal.org/download.html
7.2 unzip
7.3 fix cmake files
7.3.1 in $(CGAL)/cmake/modules/FindBoost.cmake
at line 569
if (MSVC90)
SET (_boost_COMPILER "-vc90")
add after that
elseif (MSVC10)
SET (_boost_COMPILER "-vc100")
7.3.2 in $(CGAL)/cmake/modules/CGAL_GeneratorSpecificSettings.cmake
at line 11
if ( MSVC90 )
set(CGAL_TOOLSET "vc90")
message( STATUS "Using VC90 compiler." )
add after that
elseif ( MSVC10 )
set(CGAL_TOOLSET "vc100")
message( STATUS "Using VC100 compiler." )
7.4 change GMP and MPFR lib name
CGAL will find GMP and MPFR lib name like $()-vc??-mt.lib
so please change "mpir.lib" to "gmp-vc100-mt.lib"
"mpfr.lib" to "mpfr-vc100-mt.lib"
7.5 use cmd.exe
and go to $(CGAL_DIR)
run cmake .
7.6 There si small bug in mpfr.h
at line 298 add #include
it fixed at version 2.4.2, however, i did not try this one.
7.6 open $(CGAL_DIR)/CGAL.sln
run release
7.7 fix auto_link.h
at $(CGAL_DIR)/include/CGAL/auto_link/auto_link.h
at line 141
original:
#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1500)
// vc90:
# define CGAL_LIB_TOOLSET "vc90"
change to:
#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1500)
// vc90:
# define CGAL_LIB_TOOLSET "vc90"
#elif defined(BOOST_MSVC) && (BOOST_MSVC > 1500)
// vc10:
# define CGAL_LIB_TOOLSET "vc100"
congratulations!! you finish installing CGAL
you can run some example from there
http://acg.cs.tau.ac.il/cgal-at-tau/installing-cgal-and-related-programs-on-windows
snapshot of the example
good luck!
note:
if your program can not find mpir.dll, just copy mpir.dll to your root of program
1.1. There is remark that you need to change CMakeVS10FindMake.cmake
where is that ?
If using Binary distribution, it will be $(CMAKE_DIR)\share\cmake-2.8\Modules
If you like to complie by yourself, it will be &(CMAKE_DIR)\Modules
1.2 To complie by yourself, you need to change the file first, and download cmake Binary to make project(it sounds wired but please see Installing CMake).
1.3 After making project, you can use Visual Studio 2010 to make binary
Sample open .sln file and run release
2. Configure your "system envirnoment", add $(CMAKE_DIR)\bin in "path" for you can execute cmake anytime.
For Binary ditribution: $(CMAKE_DIR)\bin (example)
For src compiled: $(CMAKE_DIR)\bin\$(OUTDIR)
3. Install Boost (latest 1.43.0)
because boostpro do not support vs 2010, you have to compile by yourself.
3.1 download Boost http://www.boost.org/users/download/
3.2 for build Boost "Boost Jam" http://sourceforge.net/projects/boost/files/boost-jam/3.1.18/
3.3 copy bjam.exe to $(boost_DIR)
3.4 run bjam --build-dir="d:\build-boost" --build-type=complete msvc
build-dir: is the dir to work
build-type=complete means to build all
remark: I have try skip this, and it works.
it takes about 1 hr to build complete, and about 20 min to do default
after building, file will in $(BOOST_DIR)/stage/lib
3.5 add "system environment" in "path" add "$(BOOST_DIR)"
this for CGAL know where is BOOST
4. Install Exact Arithmetic
CGAL support GMP+MPFR, MPFI, LEDA
This time the program I use only needs GMP + MPFR
CGAL said they provide precompile GMP + MPFR, but they do not support 2010 at this time.
Everything have do by yourself.
GMP is not support visual Studio. (may they don't like M$)
Luckly, there is someone porting to visual studio call MPIR
4.1 install MPIR
download from http://www.mpir.org/#release
they even have visual studio 2010 version very cool.
Sample unzip and open .sln
run release.
copy all ".h" file in the $(outdir) to $(CGAL)/auxiliary/gmp/include
copy all .lib and ".dll" file in the $(outdir) to $(CGAL)/auxiliary/gmp/lib
4.2 install MPFR
again, MPFR does not support VS
you can find someone provide vs 2008 project file here http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php
just download here
4.2.1 download MPFR http://www.mpfr.org/
because the project support 2.4.1 only, I use version 2.4.1
4.2.2 copy vs 2009 project file to $(MPFR_DIR)
4.2.3 copy all MPIR in $(OUT_DIR) files to $(MPFR_DIR)/../mpir
4.2.4 run $(MPFR_DIR)/build.vc9/lib_mpfr.sln
vs2010 will convert for you. it takes about 2 mins
change the lib_mpfr property... / configuration Property / Librarian /
additional Dependencies
../../mpir/....... -> ../../mpir/mpir.lib (or the path you put mpir.lib)
and run release..
4.2.5 run $(MPFR_DIR)/build.vc9/dll_mpfr.sln
change the dll_mpfr property... / configuration Property / Linker /
additional Dependencies
../../mpir/....... -> ../../mpir/mpir.lib (or the path you put mpir.lib)
and run release..
4.2.6 copy all ".h" file in the $(outdir) to $(CGAL)/auxiliary/gmp/include
copy all .lib and ".dll" file in the $(outdir) to $(CGAL)/auxiliary/gmp/lib
copy $(mpfr)/mpfr.h to $(CGAL)/auxiliary/gmp/include
5. Visualization
5.1 install Qt
Qt is going to support windows 7 and visual Studio 2010 at version Qt 4.7
so I download Qt 4.7 beta filename: qt-everywhere-opensource-src-4.7.0-beta1
5.2 unzip and set environments
environments set PATH += $(QT_DIR)/bin
set LIB += C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
set Include += C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include
5.3 fix some error
in $(QTDIR)\src\3rdparty\webkit\JavaScriptCore\runtime
at line 171
transitionTable()->add(key, Transition(structure, 0));
change to
transitionTable()->add(key, Transition(structure, nullptr));
at line 178
transitionTable()->add(key, Transition(0, structure));
change to
transitionTable()->add(key, Transition(nullptr, structure));
5.4 run configure at $(QT_DIR) using Visual Studio Command Prompt
because Qt didn't support vs2010, just use vs2008 setting
configure.exe -platform win32-msvc2008 -fast
on internet there is simple run command (less warning and no error): http://stackoverflow.com/questions/1644172/building-qt-4-5-with-visual-c-2010
configure.exe -platform win32-msvc2008 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
you can choose any one is ok.
5.5 nmake
it takes long time if there is no error.
5.6 you finish installing QT
6. Miscellaneous
I didn't use this, so Skip this part
7. install CGAL
7.1 download CGAL http://www.cgal.org/download.html
7.2 unzip
7.3 fix cmake files
7.3.1 in $(CGAL)/cmake/modules/FindBoost.cmake
at line 569
if (MSVC90)
SET (_boost_COMPILER "-vc90")
add after that
elseif (MSVC10)
SET (_boost_COMPILER "-vc100")
7.3.2 in $(CGAL)/cmake/modules/CGAL_GeneratorSpecificSettings.cmake
at line 11
if ( MSVC90 )
set(CGAL_TOOLSET "vc90")
message( STATUS "Using VC90 compiler." )
add after that
elseif ( MSVC10 )
set(CGAL_TOOLSET "vc100")
message( STATUS "Using VC100 compiler." )
7.4 change GMP and MPFR lib name
CGAL will find GMP and MPFR lib name like $()-vc??-mt.lib
so please change "mpir.lib" to "gmp-vc100-mt.lib"
"mpfr.lib" to "mpfr-vc100-mt.lib"
7.5 use cmd.exe
and go to $(CGAL_DIR)
run cmake .
7.6 There si small bug in mpfr.h
at line 298 add #include
it fixed at version 2.4.2, however, i did not try this one.
7.6 open $(CGAL_DIR)/CGAL.sln
run release
7.7 fix auto_link.h
at $(CGAL_DIR)/include/CGAL/auto_link/auto_link.h
at line 141
original:
#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1500)
// vc90:
# define CGAL_LIB_TOOLSET "vc90"
change to:
#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1500)
// vc90:
# define CGAL_LIB_TOOLSET "vc90"
#elif defined(BOOST_MSVC) && (BOOST_MSVC > 1500)
// vc10:
# define CGAL_LIB_TOOLSET "vc100"
congratulations!! you finish installing CGAL
you can run some example from there
http://acg.cs.tau.ac.il/cgal-at-tau/installing-cgal-and-related-programs-on-windows
snapshot of the example
good luck!
note:
if your program can not find mpir.dll, just copy mpir.dll to your root of program
Boost及CGAL安装配置指南
1, 首先安装Boost,下载最新的boost ,解压到某个目录
首先要编译生成boost安装工具bjam
进入boost目录执行:
./bootstrap.sh
然后执行刚生成的
./bjam
编译开始,大约半小时,全部编译结束。
./bjam install 将当前目录下编译好的头文件拷贝到相应位置:在/usr/local/include下有头文件夹boost,在/usr/local/lib下有boost的库
2, 安装MPFR、GMP、geomview(可视化)和 libQGLViewer
sudo apt-get install libgmp3-dev libmpfr-dev
sudo apt-get install geomview
下载 libqglviewer-devel_2.3.5_i386.deb(头文件及文档)和 libqglviewer_2.3.5_i386.deb(库文件),鼠标点击安装即可。 这时要重新做一个库文件的符号链接,
cd /usr/lib/
ln -sf libQGLViewer.so.2.3.4 libqglviewer.so
3, 安装qt3, qt4
sudo apt-get install libqt4-dev
sudo apt-get install libqt3-disigner
4, 下载最新的 CGAL, 它要要求boost要1.34.1以上。
cmake-gui .
make
sudo make install
默认头文件装在 usr/local/include/, 库文件装在 usr/local/lib/.
5,使用CGAL编译代码
复制scripts/cgal_create_cmake_script到你的工程目录,运行下列命令,将地址替换成你当前的工作目录
cmake -DCGAL_DIR=$HOME/CGAL-3.5
然后运行make,即可生成可执行文件
首先要编译生成boost安装工具bjam
进入boost目录执行:
./bootstrap.sh
然后执行刚生成的
./bjam
编译开始,大约半小时,全部编译结束。
./bjam install 将当前目录下编译好的头文件拷贝到相应位置:在/usr/local/include下有头文件夹boost,在/usr/local/lib下有boost的库
2, 安装MPFR、GMP、geomview(可视化)和 libQGLViewer
sudo apt-get install libgmp3-dev libmpfr-dev
sudo apt-get install geomview
下载 libqglviewer-devel_2.3.5_i386.deb(头文件及文档)和 libqglviewer_2.3.5_i386.deb(库文件),鼠标点击安装即可。 这时要重新做一个库文件的符号链接,
cd /usr/lib/
ln -sf libQGLViewer.so.2.3.4 libqglviewer.so
3, 安装qt3, qt4
sudo apt-get install libqt4-dev
sudo apt-get install libqt3-disigner
4, 下载最新的 CGAL, 它要要求boost要1.34.1以上。
cmake-gui .
make
sudo make install
默认头文件装在 usr/local/include/, 库文件装在 usr/local/lib/.
5,使用CGAL编译代码
复制scripts/cgal_create_cmake_script到你的工程目录,运行下列命令,将地址替换成你当前的工作目录
cmake -DCGAL_DIR=$HOME/CGAL-3.5
然后运行make,即可生成可执行文件
2010年10月26日星期二
虚函数
虚函数的作用是实现动态联编,也就是在程序的运行阶段动态地选择合适的成员函数,在定义了虚函数后,可以在基类的派生类中对虚函数重新定义,在派生类中重新定义的函数应与虚函数具有相同的形参个数和形参类型。以实现统一的接口,不同定义过程。如果在派生类中没有对虚函数重新定义,则它继承其基类的虚函数。
当程序发现虚函数名前的关键字virtual后,会自动将其作为动态联编处理,即在程序运行时动态地选择合适的成员函数。 动态联编规定,只能通过指向基类的指针或基类对象的引用来调用虚函数,其格式: 指向基类的指针变量名->虚函数名(实参表) 或 基类对象的引用名. 虚函数名(实参表) 虚函数是C++多态的一种表现 例如:子类继承了父类的一个函数(方法),而我们把父类的指针指向子类,则必须把父类的该函数(方法)设为virtual(虚函数)。 使用虚函数,我们可以灵活的进行动态绑定,当然是以一定的开销为代价。 如果父类的函数(方法)根本没有必要或者无法实现,完全要依赖子类去实现的话,可以把此函数(方法)设为virtual 函数名=0 我们把这样的函数(方法)称为纯虚函数。 如果一个类包含了纯虚函数,称此类为抽象类 。
当程序发现虚函数名前的关键字virtual后,会自动将其作为动态联编处理,即在程序运行时动态地选择合适的成员函数。 动态联编规定,只能通过指向基类的指针或基类对象的引用来调用虚函数,其格式: 指向基类的指针变量名->虚函数名(实参表) 或 基类对象的引用名. 虚函数名(实参表) 虚函数是C++多态的一种表现 例如:子类继承了父类的一个函数(方法),而我们把父类的指针指向子类,则必须把父类的该函数(方法)设为virtual(虚函数)。 使用虚函数,我们可以灵活的进行动态绑定,当然是以一定的开销为代价。 如果父类的函数(方法)根本没有必要或者无法实现,完全要依赖子类去实现的话,可以把此函数(方法)设为virtual 函数名=0 我们把这样的函数(方法)称为纯虚函数。 如果一个类包含了纯虚函数,称此类为抽象类 。
虚函数的实例
#include<iostream.h>class Cshape{ public: void SetColor( int color) { m_nColor=color;}void virtual Display( void) { cout<<"Cshape"<<endl; }private:int m_nColor;};class Crectangle: public Cshape{public:void virtual Display( void) { cout<<"Crectangle"<<endl; }};class Ctriangle: public Cshape{void virtual Display( void) { cout<<"Ctriangle"<<endl; }};class Cellipse :public Cshape{public: void virtual Display(void) { cout<<"Cellipse"<<endl;}};void main(){Cshape obShape;Cellipse obEllipse;Ctriangle obTriangle;Crectangle obRectangle;Cshape * pShape[4]={ &obShape, &obEllipse,&obTriangle, & obRectangle };for( int I= 0; I< 4; I++)pShape[I]->Display( );}本程序运行结果:CshapeCellipseCtriangleCrectangle条件
所以,从以上程序分析,实现动态联编需要三个条件:1、 必须把动态联编的行为定义为类的虚函数。2、 类之间存在子类型关系,一般表现为一个类从另一个类公有派生而来。3、 必须先使用基类指针指向子类型的对象,然后直接或者间接使用基类指针调用虚函数。2010年10月23日星期六
订阅:
评论 (Atom)
