How do I specify that CMake should use a different link_directories
value depending on whether the target is 32-bit or 64-bit? For example, 32-bit binaries need to link with 32-bit Boost, 64-bit binaries need to link with 64-bit Boost.
相关问题
- Direct2D Only Partially Linking in C++ Builder
- What are the recommended GNU linker options to spe
- What is the right order of linker flags in gcc?
- Avoid cmake to add the flags -search_paths_first a
- CMakeList file to generate LLVM bitcode file from
相关文章
- MPI and D: Linker Options
- Weakly link static library via -weak_library
- Target requires the language dialect “CXX17” (with
- How do I tell cmake not to create a console window
- Linker Trouble: How to determine where a “/DEFAULT
- static const in c++ class: undefined reference
- Do something for all targets
- CMake: Replace compile flags of an INTERFACE targe
I know it's quite old question. But it's still on top when you search with Google "cmake 32 64". I have answer similar to user434507's answer but a little bit more readable in my opinion (I don't like if-else construction in cmake, it looks ugly):
This will point
BOOST_LIBRARY
path to /boost/win32/lib or /boost/win64/lib, depending on your architecture.You do something along these lines
For Boost specifically, you should use
FIND_LIBRARY(Boost 1.44 COMPONENTS ...)
Then the CMake variable Boost_LIBRARY_DIRS will contain the correct library path, which has to be set using LINK_DIRECTORIES, e.g.
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
The more general case is correctly described in user434507's answer.
Based on rominf I turned up following solution (for Windows). I install boost libraries into: C:\Boost_32 and C:\Boost_64
In CMakeLists.txt
Explanation:
CMAKE_SIZEOF_VOID_P
is equal to 4 on 32bit platform, and 8 on 64bit platform.8*${CMAKE_SIZEOF_VOID_P}
will evaluate to 32 or 64, respectively.C:/Boost_${BITS}
turns intoC:/Boost_32
orC:/Boost_64
automagicallyAdvantages: