Notes about boost library installation and compilation

Source: Internet
Author: User

Environment: Linux s12084 2.6.9-67. elsmp #1 SMP wed Nov 7 13:58:04 est 2007 i686 i686 i386 GNU/Linux

GCC version 3.2.3 20030502 (Red Hat Linux 3.2.3-47.3)

Boost 1.37.0

I used it again in March. We are using the RegEx library today. Note. For future reference.

The boost library is really good. Compilation on Windows and Linux platforms is successful. Hp acc also claims full support for Boost 1.35.

Compiling all is a very painful process. If you want to use a library, you only need to find the library you are interested in under $ (boost_root)/libs/. In the build directory, select the makefile used by the compiler and compile it.

For example, I use the RegEx library of boost 1.37. The root directory of the boost package is c: \ boost_1_37_0.

Then go to the directory below

C: \ boost_1_37_0 \ libs \ RegEx \ build

You can see a lot of. Mak files. You can see which. Mak file you need based on the name. Here I use the GCC compiler, so select GCC. Mak.

The compiler can generate eight libraries based on makefile files or parameters. Static \ Dynamic, release \ debug, multi-thread \ single-thread library. According to the name, the debug version has one "_ d" more than other versions, and the multi-thread version has one "_ MT" more than other versions ". The list of file names generated by the RegEx library in Linux is as follows:

// Two versions of the dynamic library

Libboost_regex-gcc-1_37.so libboost_regex-gcc-d-1_37.so

// Two static library versions

Ibboost_regex-gcc-1_37.a libboost_regex-gcc-d-1_37.a

// Two dynamic multi-threaded versions

Libboost_regex-gcc-mt-g037.so libboost_regex-gcc-mt-d-1_37.so

// Two static multi-threaded versions

 

Libboost_regex-gcc-mt-g037.a libboost_regex-gcc-mt-d-1_37.a

 

Compilation will be completed in a short time. The library file generated after compilation is in.

In makefile, you must use the-I option to add the path to the boost root directory. If you use a dynamic connection library, you also need to add a reference to the. So file in the-L option. The following is a detailed explanation.

 

 

Boost: RegEx Problems

From: http://bbs.chinaunix.net/viewthread.php? Tid = 987718

The RegEx is compiled separately and the libboost_regex-gcc-1_34.a is generated. The Code is as follows: Code: # include <boost/RegEx. HPP>.

Int main (INT argc, char * argv [])
{
Boost: RegEx E ("test ");
Return 0;
}

# G ++ RegEx. cpp-I/path/to/boostroot-L/path/to/libboost_regex-gcc-1_34.a-O RegEx
Error:
/Tmp/ccf4wli8. O (. GNU. linkonce. t. _ prop + 0x13): In function 'boost: basic_regex <char, boost: regex_traits <char, boost: cpp_regex_traits <char >> :: assign (char const *, char const *, unsigned INT )':
: Undefined reference to 'boost: basic_regex <char, boost: regex_traits <char, boost: cpp_regex_traits <char >:: do_assign (char const *, char const *, unsigned INT )'
Collect2: LD returned 1 exit status

The header file can be found, but the database connection seems to be faulty. However, the library path should be correct. What is the problem?

Isn't the boost document clear? (Boost_000034_1/more/getting_started/unix-variants.html section 6th)

Quote:.
You can specify the full path to each library:
$ C ++-I path/to/boost_000034_1 example. cpp-O example"
~ /Boost/lib/libboost_regex-gcc34-mt-d-1_34.aQUOTE: B.
You can separately specify a directory to search (with-ldirectory) and a library name to search for (with-llibrary, 2 dropping the filename's leading lib and trailing suffix (. a In this case ):

$ C ++-I path/to/boost_000034_1 example. cpp-O example"
-L ~ /Boost/lib/-lboost_regex-gcc34-mt-d-1_34

I am using. So. So my makefile is:

Cxxflags =-lgcc_s $(LIB)-lboost_regex-gcc-d-1_37
Compile. c =$ (CC)-C $ (include)
Makeexe = $ (CC) $ (cxxflags)
# If you want. O to be generated by the executable file in the directory where the dependent file is located, you can use the path, such as./pub/B. O.
OBJ = regex_match_example.o
EXE = winner

ALL: $ (exe)
$ (Exe): $ {OBJ}
# '$ ^', '$ @' Is called "automatic variables". The information provided by vpath is used to find the corresponding file.
$ (Makeexe) $ ^-o $ @
%. O: %. cpp
$ (Compile. c) $ ^-o $ @
Clean:
Rm-f *. o $ (exe) Core

 

After compilation, copy the dynamic Connection Library to the current directory.

 

The system prompts that the dynamic Connection Library cannot be found.

./Winner: Error while loading shared libraries: libboost_regex-gcc-d-1_37.so: cannot open shared object file: no such file or directory

 

Let's take a look at the reference information of the program and the version information of the connected database. It's OK:

 

Use LDD to view the dynamic connection library information of a file, and use file to view the version information of the dynamic Connection Library.

[Fancp @ s12084 test] $ LDD winner
/Lib/libcwait. So (0x00de9000)
Libgcc_s.so.1 =>/lib/libgcc_s.so.1 (0x00db1000)
Libboost_regex-gcc-d-1_37.so => not found
Libstdc ++. so.5 =>/usr/lib/libstdc ++. so.5 (0x00340000)
Libm. so.6 =>/lib/tls/libm. so.6 (0x00b51000)
Libc. so.6 =>/lib/tls/libc. so.6 (0x00a23000)
/Lib/ld-linux.so.2 (0x00a04000)
[Fancp @ s12084 test] $ file libboost_regex-gcc-d-1_37.so
Libboost_regex-gcc-d-1_37.so: Elf 32-bit LSB shared object, Intel 80386, Version 1 (sysv), not stripped
[Fancp @ s12084 test] $

Check that the current directory is not added to Lib in the environment variable as the search path.

Modify the. bash_profile file, add a colon to the Lib, save the file, exit shell, and enter again. OK!

 

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.