2014-09-30更
fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
Check:
Project Properties -> Configuration Properties -> Linker -> Command line.
"Additional Options" should NOT contain /machine:X86
I have such key, generated by CMake output: CMake generated x86 project, then I added x64 platform via Configuration Manager
in Visual Studio 2010 - everything was updated fine except linker command line, specified /machine:X86
separately.
1. 起因
需要编译bgslibrary。用到了OpenCV。为了跨平台遍历文件,我用了boost filesystem.
Boost 库使用Boost.Build作为跨平台编译工具。也就相当于CMake?
2. Linux
照基本教程,没有任何问题
Getting Started on Unix variants (e.g. Linux, MacOS)
3. Windows
首先,boost default build with shared library output., from Linker error LNK1104 with 'libboost_filesystem-vc100-mt-s-1_49.lib'
而bgslibrary自带的VS. project 默认静态连接 (/MT 选项)
其次,改成/MD后还是有unresovled reference 错误。怀疑是64位的问题。
用 b2 architecture=x86 address-model=64 stage 重编译一遍,解决!!
结论: Windows下Boost 默认编译32位的动态链接库版本
4. Mac
Mac ML 包括了两个标准C++库: libstdc++(GNU C)和libc++(clang)。MacPorts中编译的boost和OpenCV都默认连接libstdc++
最后编译成功的命令行
./bootstrap.sh --with-toolset=clang --prefix=./build-boost155/
./b2 --build-dir=`pwd`/build-boost155/build/ --stagedir=`pwd`/build-boost155/stage/ toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" define=BOOST_SYSTEM_NO_DEPRECATED install
可以查看动态库连接的是libc++还是libstdc++
otool -L /opt/local/lib/libboost_filesystem-mt.dylib
otool -L /opt/local/lib/libboost_filesystem-mt.a
How do I compile boost for OS X 64b platforms with stdlibc++?
find . -name \*.o -print0 | xargs -0 rm
find . -name \*.a -print0 | xargs -0 rm
nm ./test | c++filt
How to compile/link Boost with clang++/libc++?
$ ./b2 clean
$ ./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
You need to rebuild boost using clang++ -stdlib=libc++.
Why can't clang with libc++ in c++0x mode link this boost::program_options example?
4.1 OpenCV 2.4.8 with C++11 on OS X 10.8.5
印象中好像直接修改CMakeLists.txt 中的CMAKE_C_FLAGS或CMAKE_CXX_FLAGS不管用。好像是通过cmake-gui手动选择/usr/bin/clang和在GUI中填-std=c++11 -stdlib=libc++才行
OpenCV with C++11 on OS X 10.8
message("Setting up Xcode for C++11 with libc++.") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
opencv for ios 5.1 (on OS X 10.8) with boost using c++11 and libc++
5. 其他
顺便搞懂了几个问题
CRT Library Features
boost lib build configuraton variations
[lib][boost_unit_test_framework]-[vc80]-[mt]-[sgd]-[1_35][.lib]
lib
: On Linux all files are prefixed with this- On Windows this prefix is not on "import libraries and DLLs"
boost_unit_test_framework
: The library name beginning withboost_
vc80
: Toolset and version used to build this libraryvc71
: Microsoft Visual C++ 2003 (version 7.1)vc80
: Microsoft Visual C++ 2005 (version 8.0)
mt
: Indicates multithreading supportsgd
: Each letter indicates somethings
: Static linkingg
: Linked to debug librariesy
: "using a special debug build of Python"d
: Boost debugp
: Uses "the STLPort standard library"n
: using STLPort's deprecated "native iostreams" feature
1_35
: Boost version.lib
: Extension varies based on convention in operating system
Using libstdc++ compiled libraries with clang++ -stdlib=libc++
最好不要混用
he libstdc++ std::string
is a different data structure than the libc++ std::string
. The former is a reference counted design, whereas the latter is not. Although they are API compatible, they are not ABI compatible.
6. 疑问
Bjam和b2和bootstrap是不是一回事?配置参数好像都一样,一会有”--“一会没有,很confusing啊
bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete stage
Problem Linking Boost Filesystem Library in Microsoft Visual C++
b2 --build-dir=build-directory toolset=toolset-name stage
./bootstrap.sh --with-toolset=clang
./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++"
Compile boost 1.52 C++11 clang mac 10.8.2 cannot find cstddef
/b2 --build-dir=../boost_libs toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" stage --with-filesystem
Having trouble compiling boost filesystem's tutorial file