Visual Studio 2008 Compiling the Machine learning algorithm library shark

Source: Internet
Author: User

Shark is a fast, modular, feature-rich, open-source C + + machine learning Library. It realizes linear and nonlinear optimization, learning algorithm based on kernel function, neural network and many other machine learning algorithms. Shark relies on cmake and boost for compatibility with Windows, Solaris, MacOS x, and Linux. Currently the latest official version is Shark 3.0, you can get the source code from the project's SVN (click the Open link)

This article describes the complete process of compiling Shark 3.0 source code on Windows 7 (64-bit) based on Visual Studio 2008 and installing it, as well as explaining the issues that arise during installation. This process relies on CMake 3.2.1 (click to open link) and boost 1.57.0 (click the Open link).

First, install boost with Visual Studio 2008 compilation. Open Visual Studio Command Prompt under the Visual Studio Tools directory, enter the Boost directory (here D:\code\boost_1_57_0), and enter the following command:

Bootstrap--prefix= "C:\Program files\boost_1_57_0"

The results of the operation are as follows:


Booststrap will generate B2.exe and Bjam.exe in the current directory, as shown in. B2 is the engine of the entire Boost.build build system, which was implemented by Bjam in earlier versions of Boost, and Bjam was renamed as B2 from Boost 1.47.0, and Bjam was retained in view of compatibility issues.


Execute the following command in the current directory:

B2--build-type=complete--toolset=msvc-9.0--layout=versioned--prefix= "C:\Program files\boost_1_57_0"-- Without-mpi Install

where the parameter "--build-type=complete" allows Boost.build to build all the versions supported by the library; "--toolset=msvc-9.0" means the toolset for compiling boost is the Msvc 9.0 toolset, The toolset corresponds to Visual Studio 2008. "--layout=versioned" means that the Boost.build generated library file name should contain the boost version number, the compiler name and version number, and some other build properties; "--prefix=c:\program files\boost_1_ 57_0 "Specifies the boost header file and the storage directory of the build library;"--without-mpi "requires boost.build not to build an MPI library (message passing Interface, a library for messaging in high-performance parallel computing. In some versions of Boost, the "dumplicate name" error may occur when generating an MPI library. When the above process is complete (approximately 30 minutes, depending on the machine), the include and Lib two directories will be generated in the specified directory (C:\Program files\boost_1_57_0 here), so that the boost is compiled and built, The next procedure is to compile and build the shark.

Then open CMake and set both the source directory and the build directory to the Shark root directory (D:\code\Shark here), as shown in:


Click "Add Entry" to set the cache entry for CMake (you can also use the command line method, refer to CMake official documentation). First add the bool type parameter boost_no_system_paths, as shown (note that the Value check box indicates that this bool value is set to True):


Then add the path parameter boost_root, which specifies the directory where the Boost library is located (C:\Program files\boost_1_57_0 here), as shown in:


When you have finished setting the parameters, click the "Configure" button and select the constructor "Visual Studio 9 2008" as shown in:


when the above configuration is complete, the Configure process starts and the process generates a series of configure files. After running successfully, click the "Generate" button to generate the appropriate Visual Studio project file (. vcproj) and solution file (. sln).


After executing generate, generate the Shark.sln file in the shark root directory, open with visual Studio 2008 to see all 240 projects, as shown in:


To modify the Include/shark/algorithms/trainers/rftrainer.h file, add the following code:

#include <set>

Build the entire shark solution in debug and release mode, ignoring all warnings to get the appropriate library file.

Some of the errors you may encounter while compiling the installation shark :

1. In the process of configure with CMake, the following error message appears:

CMake Error at C:/Program Files (x86)/cmake/share/cmake-3.2/modules/findboost.cmake:1182 (message):  Unable to find The requested Boost libraries.  Boost version:1.57.0  boost include Path:c:/program files/boost_1_57_0/include/boost-1_57  Could not find the Following static Boost libraries:          boost_system          boost_date_time          boost_filesystem          BOOST_PROGRAM_ Options          boost_serialization          boost_thread          boost_unit_test_framework  No boost libraries were found .  Need to set Boost_librarydir to the  directory containing BOOST libraries or boost_root to the location Of
   boost.call Stack (most recent call first):  cmakelists.txt:168 (Find_package)
Possible cause: Boost_root set error, resulting in CMake unable to find the BOOST installation directory, when executing B2, the Toolset did not select or select an error, resulting in the generated BOOST library file name does not contain or mistakenly contain the compiler name and version information.

2. Compile the link Shark.sln process, the following compilation error occurred:

Shark\include\shark/algorithms/trainers/rftrainer.h (168): Error C2976: ' Std::set ': too few template arguments

Possible cause: The RFTrainer.h file does not contain a set header file.

3. During the compile link Shark.sln, the following (or similar) Link error occurred:

Link:fatal Error Lnk1104:cannot Open file ' Libboost_serialization-vc90-mt-gd-1_57.lib '

Possible cause:boost_root Setup error, resulting in CMake unable to find the BOOST installation directory, the layout parameter is not set to versioned when executing B2, resulting in the generated BOOST library file name does not contain the compiler name and version information.

4. Some projects have the following (or similar) compilation errors:

Shark\include\shark/models/kernels/multitaskkernel.h: Error C2529: ' abstract declarator ': reference to reference is illegal

Possible cause: The reference is illegal. Shark 3.0 uses a large number of C + + templating techniques, often with double references. The possible solution is to use the call trait mechanism provided by boost to replace the parameters of some member functions in the template class with an equivalent expression in call_traits, or to replace the updated version of the compiler.

Visual Studio 2008 Compiling the Machine learning algorithm library shark

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.