3

我将 boost.build 用于我的项目。当然,我使用 boost 本身。此外,出于测试目的,我在我的项目中使用了 google-test 库。我必须将我的项目与 google-test 的静态库链接起来。我找到了为 MinGW 执行此操作的解决方法(对于 linux 的 gcc 也可以)

exe foo : $(IMPORTANT_PART) $(TEST_UTILITY_PART) : <toolset>gcc <linkflags>"../../libs/gtest-1.6.0/libs/gtest_main.a" <linkflags>-static <linkflags>-lpthread ;

它看起来有点难看,但它确实有效。msvc 的规则看起来要丑得多

exe foo : $(IMPORTANT_PART) $(TEST_UTILITY_PART) : <toolset>msvc <linkflags>/LIBPATH:../../libs/gtest-1.6.0/libs <linkflags>/DEFAULTLIB:gtest_main-mdd.lib
<linkflags>/DEFAULTLIB:gtestd-md.lib
;

是否有更自然的方式将目标与 boost.build 项目文件中的外部静态库链接。


PS 当然,使用 google-test 和 boost mix 的味道并不好,但无论如何,有很多外部库覆盖了 boost 没有涵盖的领域。

TIA

4

1 回答 1

1

伟大的!感谢指出我http://www.boost.org/boost-build2/doc/html/bbv2/tutorial/prebuilt.html页面的人。(评论消失了)似乎是,我确实没有仔细阅读此页面。具有文件属性的目标库执行我搜索的操作。谢谢!


至于使用 google test 和 boost build,我是这样做的:我为 google-test 制作了 Jamfile。这很简单:

gtest.lib/Jamfile
    project gtest_main 
         : requirements <include>../../../libs/gtest-1.6.0/include
                        <include>../../../libs/gtest-1.6.0/
         : source-location ../../../libs/gtest-1.6.0 
         : build-dir ../../../libs/gtest-1.6.0/bin.b2 ; 
    
    lib gtest_main : src/gtest_main.cc src/gtest-all.cc : <link>static ;

然后,在我的项目文件中的某处:

使用项目 /gtest : ./gtest.lib ;

并在项目的需求部分提到 //gtest。

于 2012-12-17T21:01:14.913 回答