Boost编译库在x86和x64上有相同的名称。我的项目使用了Boost,我希望在使用CMake为x64或x86目标编译时,它能自动链接到正确的Boost库。
我的CMakeFiles.txt文件中使用了简单的代码。
我的CMakeFiles.txt文件中使用了简单的代码。
find_package(Boost REQUIRED
COMPONENTS
coroutine context thread filesystem program_options system
)
我的 Boost 是使用 MSVC2015 构建的。
b2 address-model=32 --build-type=minimal stage --stagedir stage
b2 address-model=64 --build-type=minimal stage --stagedir stage64
我也尝试过“安装”目标并将boost构建放入单独的文件夹中
我正在(Windows)上构建我的项目
md build32
cd build32
cmake .. -G"Visual Studio 14 2015"
cmake --build .
cd ..
并且
md build
cb build
cmake .. -G"Visual Studio 14 2015 Win64"
cmake --build .
cd ..
因为x86库(boost)位于“stage”文件夹中,而CMake的FindBoost模块熟知该文件夹,所以x86目标构建成功。
但是x64目标无法构建,因为FindBoost在构建过程中使用了Boost的x86库,并且不尝试使用“stage64”中的库,出现以下错误:
D:\lib\boost_1_61_0\stage\lib\libboost_coroutine-vc140-mt-gd-1_61.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
我的目标是在“Cmake”调用时排除任何其他参数,使其自动找到正确的x86或x64 Boost库,具体取决于我使用的CMAKE的-G参数。
我应如何更改我的CMakeFiles.txt才能使其自动查找正确的Boost库?
Boost版本-1.61,MSVC 2015,CMAKE-3.6.2(最新版本并熟知Boost 1.61),Windows 7 x64。
BOOST_ROOT
设置为适当的目录(D:\lib\boost_1_61_0\stage64
)。 - TsyvarevBOOST_ROOT/lib32-msvc-14.0/
,将x64库放入BOOST_ROOT/lib64-msvc-14.0/
,然后再次检查吗? - llonesmizstage32
而不是仅仅使用stage
。问题似乎在于BOOST_ROOT/stage/lib
被无条件地添加到CMake查找库的目录列表中。 - llonesmizBOOST_ROOT
。 - Dan Mašek