qt使用boost

打开cmd,进入boost库所在的目录 
找到build.bat,然后执行以下命令编译b2和bjam

build mingw
  • 1

我的build.bat在F:\boost_1_56_0\tools\build\src\engine 
编译完之后在当前目录会生成一个bin.ntx86的目录,进入后有b2.exe和bjam.exe可执行文件,将这两个文件拷贝到boost源代码的根目录下

执行安装

bjam --toolset=gcc --prefix=D:\boost\bin install
  • 1

下面就慢慢的等待吧,需要很久的时间 
完成之后可以在刚才指定的目录中找到编译好的库。

在qt中引用库

添加头文件目录

在项目文件*.pro中添加以下信息(我的头文件都是在F:\boost\bin\include\boost下面,该目录下面有很多的.hpp文件)

INCLUDEPATH += D:/boost/bin/include
  • 1

引用库文件(我生成的所有的*.a文件都在D:/boost/bin/lib/下面)

LIBS +=D:\boost\bin\lib\libboost_atomic-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_chrono-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_container-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_context-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_contract-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_coroutine-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_date_time-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_exception-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_filesystem-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_graph-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_iostreams-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_locale-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_log-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_log_setup-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_math_c99-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_math_c99f-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_math_c99l-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_math_tr1-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_math_tr1f-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_math_tr1l-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_prg_exec_monitor-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_program_options-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_random-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_regex-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_serialization-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_signals-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_stacktrace_noop-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_stacktrace_windbg-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_system-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_test_exec_monitor-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_thread-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_timer-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_type_erasure-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_unit_test_framework-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_wave-mgw49-mt-d-x32-1_67.a
LIBS +=D:\boost\bin\lib\libboost_wserialization-mgw49-mt-d-x32-1_67.a

java获得文件夹下的所有文件:

package test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class test {
	public static void main(String[] args) {
		List<String> allFile = getAllFile("D:\\boost\\bin\\lib", true);
		for (String string : allFile) {
			if(!string.contains("mt-x32")){
				System.out.println("LIBS +="+string);
			}
			
		}
	
	}
	public static List<String> getAllFile(String directoryPath,boolean isAddDirectory) {
        List<String> list = new ArrayList<String>();
        File baseFile = new File(directoryPath);
        if (baseFile.isFile() || !baseFile.exists()) {
            return list;
        }
        File[] files = baseFile.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                if(isAddDirectory){
                    list.add(file.getAbsolutePath());
                }
                list.addAll(getAllFile(file.getAbsolutePath(),isAddDirectory));
            } else {
                list.add(file.getAbsolutePath());
            }
        }
        return list;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_33762043/article/details/80275445