win7 + vs2010 + osg 编译安装过程

来源:互联网 发布:网络控制手机发短信 编辑:程序博客网 时间:2024/06/12 20:47

环境简述:

系统:win7 64 + vs2010

第一步:下载osg(OpenSceneGraph)

下载后解压,安装惯例,要知道怎么安装,找README.txt,一般地,它会告诉我们,下面这句是README文件中的一部分内容:

Under Windows use the GUI tool CMakeSetup to build your VisualStudio files. The following page on our wiki dedicated to the CMake build system should help guide you through the process: http://www.openscenegraph.org/index.php/documentation/platform-specifics/windows(当然了,不同的版本,这个链接可能不一样哦,要灵活)

第二步:安装README的指示,我们打开那个链接

Written by openscenegraph4206Older Visual Studio VersionsWritten by Thomas Hogarth3297Visual Studio PluginsWritten by Thomas Hogarth5586Compiling with Visual StudioWritten by Thomas Hogarth16273

第三步:我们选择Compiling with Visual Studio

说句题外话,打开这个地址后,我们能看到(它说有已经编译好的二进制版本,但是没有找到,可能这个没有更新吧):

Follows are details on usage of OpenSceneGraph from source packages. These are useful if you want to always stay up to date with the newest OSG sources from the SVN repository, or to use an OSG release that has no binaries. If you don't want this, you can probably use precompiled binaries from the Downloads page

  言归正传,继续我们的工作。

Compiling with Visual Studio .NET

(Note: These instructions are valid for Visual Studio .NET 2005 (8.0) and Visual Studio Express 2005 (see below), but they should also apply to Visual Studio .NET 2003 (7.0) or to Visual Studio .NET 2008 (9.0).)

它说:下面的指示在vs2005好使(可能是测试过吧),但我在vs2010上编译成功了,所以,放心的来吧。

第四步:按照指示走。

Initial setup

The project files are set up so that if you have the dependencies in the same base directory as the OpenSceneGraph sources, then it will find them. Thus, the suggested directory structure is:

OpenSceneGraph-VERSION (replace VERSION by 2.8 or SVN or whatever) 
OpenSceneGraph-VERSION\3rdParty (put the contents of the 3rdParty zip file in here) 
OpenSceneGraph-VERSION\OpenSceneGraph

In the OpenSceneGraph directory, see the Downloads page and download the sources for the version you're interested in, or check out the sources from the SVN repository using the SVN client of your choice (for example TortoiseSVN on Windows).

In the 3rdParty directory, see the Dependencies page and download the dependencies for your platform. Place them so that the bin, lib etc. directories are directly under OpenSceneGraph-VERSION\3rdParty .

长话短说:我们新建一个目录,我们把下载的osg解压到里面;如果我们使用3rdParty(当然了,不用应该也是可以的,但我用了),我们就把下载的3rdParty也解压到我们新建的这个目录。其实说白了就是:在编译时,为了能够让OpenSceneGraph找到3rdParty,它们俩需要在同一级目录。

第五步:仍然按照指示走。

Generating Project & Solution files with CMake

Once the sources and dependencies are in place you need to generate the Visual Studio solution and project files. This is done with CMake. Download it at http://www.cmake.org/HTML/Download.html.

Start the CMake GUI once it's installed, and select root OpenSceneGraph directory in the "Where is the source code" field. The same directory needs to be put into the "Where to build the binaries" field. If you like to do out-of-source builds, you can add \build to the end. Then click Configure.

You can then customize your build. The red lines in the CMake window indicate new variables that you may want to fill out or change, but most are optional. Some variables will be filled in automatically (such as ACTUAL_3RDPARTY_DIR, if you followed the directory structure above). I typically enable BUILD_OSG_EXAMPLES and set CMAKE_INSTALL_PREFIX to the OpenSceneGraph directory so that the binaries are installed in OpenSceneGraph\bin. You can also set it to somewhere else if you want to keep your source tree clean.

Note: In the permission-restricted environment of Windows Vista and later, do not set CMAKE_INSTALL_PREFIX to be a restricted folder like "Program Files". The make process will not be able to elevate permissions sufficiently to write to the destination, and will fail (typically while installing the first component, OpenThreads, with an error like "file INSTALL cannot copy file OpenThreads.dll").

Check if the dependencies you have are detected - if not fill in the variables manually. If you need to fill in some variables manually, you may need to show "Advanced" variables (with the drop-down at the top of the window) and make sure all relevant variables are set correctly for a given dependency. Any plugins or examples for which you don't have the dependencies will just not be part of the generated project files, which is cleaner than it was before (the projects would be there but just refuse to build, which resulted in lots of noise when building for things you knew would not build anyway).

Once your build configuration is to your liking, click Configure until the Generate button is enabled, then click that. Once it's done generating the project files, you can close CMake

ok,长话短说,它告诉我们【我们需要cmake来生成我们的vs2010的sln解决方案文件,cmake是用来根据cmakelist.txt来生成各种各样工程文件或者makefile文件的,比如vs2010,vs2008,vc6.0等等】,好了按照cmake我就不废话了,找cmake官网喽,我要说的是:因为我的系统是win7 64,但官网上没有找到windows 64的binary版本,但是win32那个还是可以用的,我就用的它。

第六步:我假设大家成功的走完了第五步中的english step,ok,我们继续。

generate之后,我们就有了一个vs2010的sln,还等什么,用vs2010打开它吧(很可恶,在我机器上,直接双击那个sln竟然不能打开,还好先打开vs,再open 这个sln是ok的)。

Building with Visual Studio

Open the generated OpenSceneGraph.sln file, which will be in the directory you entered under "Where to build the binaries" (eg. OpenSceneGraph\build), with Visual Studio. Select your desired build type (Debug, Release, RelWithDebugInfo, MinSizeRel) and press F7 for "Build Solution".Assuming everything builds correctly, you can then right-click on the INSTALL project and build that, which will copy the compiled files to the correct directories (based on what you set CMAKE_INSTALL_PREFIX to). Before that, the compiled files all reside in the build directory, and I don't recommend you use them from there.

Just to reiterate: Always build the INSTALL project. The locations where the files are copied to as part of the INSTALL target are the correct locations from where you should use them (bin\ for application executables and DLLs, lib\ for libraries, include\ for headers, and share\OpenSceneGraph\bin\ for example executables). See "Environment variables" below for some tips to set up your build environment for your own project to use the files from the correct locations.

长话短说:就是build一个这个呗(时间有点长哦,可能会超过一个小时的),build之后再install,看好上面的红色文字哦,build install后,它就会帮你安装好osg。之后你需要做的仅仅是:配置环境变量,当然,当你create一个osg工程的时候,需要引入lib,include头文件等等。

第七步:环境变量设置

我感觉我很啰嗦了,并且你可能很反感我没有翻译这些英文(但是它真的很简单的,仔细阅读一下,就当练习英语水平了),我最后再copy一段结束此文:

Environment variables

If you select the first method, a way to simplify things and to make your project files work on multiple different machines is to use some standard environment variables. I use the following:

OSG_ROOT points to the base of the OSG file structure (the directory that contains includesrc etc. subdirectories)OSG_BIN_PATH = %OSG_ROOT%\binOSG_INCLUDE_PATH = %OSG_ROOT%\includeOSG_LIB_PATH = %OSG_ROOT%\libOSG_SAMPLES_PATH = %OSG_ROOT%\share\OpenSceneGraph\binOSG_FILE_PATH = ???\OpenSceneGraph-Data-X.X

Then, add %OSG_BIN_PATH% and %OSG_SAMPLES_PATH% to your PATH environment variable. That way, not only can you run examples easily, but the latest DLLs will always be found. When starting an application, Windows looks for the required DLLs first in the executable's directory, then in the PATH.

Make sure you restart Visual Studio if it was open when you added/changed these environment variables, so that it picks up te changes.

In your project's properties, use those environment variables to get Visual Studio to find the OSG libraries. Here are the settings I use:

Properties - C/C++ - General - Additional Include Directories = $(OSG_INCLUDE_PATH)Properties - C/C++ - Preprocessor - Preprocessor Definitions = WIN32;_WIN32;NDEBUGProperties - Linker - General - Additional Library Directories = $(OSG_LIB_PATH)Properties - Linker - Input - Additional Dependencies = (any OSG library your project needs - for example: osg.lib osgGA.lib osgDB.lib osgViewer.lib osgText.lib osgUtil.lib OpenThreads.lib)

Remember to do the same thing in your project's Debug configuration, but add a d to the end of the OSG and OpenThreads library names (osg.lib becomes osgd.lib and so on). Also change NDEBUG to _DEBUG in the Preprocessor Definitions.

Once that's done, your project should be able to compile, link and run. If not, you can test your paths in a console (Start-Run, type cmd, press enter), by for example typing echo %OSG_LIB_PATH% or dir %OSG_LIB_PATH%. With those commands you should be able to see what is wrong.


0 0
原创粉丝点击