Note that there are some explanatory texts on larger screens.

plurals
  1. POLinking a static boost build into a static library under VS2012 & Win32/64
    text
    copied!<p>I'm trying to build a static library to be released as an API for a network device. I can successfully compile and link the library to produce .lib output files, and I relocate them into a directory structure as follows:</p> <pre><code>EyeLib L-Include | L-PublicInterface.h L-Lib | L-debug | | L-MyLib.lib | | L-MyLib.pdb | L-release | L-MyLib.lib L-MyLibConfig.cmake </code></pre> <p>Where the MyLibConfig.cmake file is extremely simple, and contains:</p> <pre><code># the header file is relative to this cmake file, so get the path. GET_FILENAME_COMPONENT( MyLib_TOPLEVEL_DIR ${CMAKE_CURRENT_LIST_FILE} PATH ) SET( MyLib_INCLUDE_DIR ${MyLib_TOPLEVEL_DIR}/include ) IF( WIN32 ) FIND_LIBRARY( MyLib_DEBUG_LIBRARY MyLib ${MyLib_TOPLEVEL_DIR}/lib/debug ) FIND_LIBRARY( MyLib_RELEASE_LIBRARY MyLib ${MyLib_TOPLEVEL_DIR}/lib/release ) SET( MyLib_LIBRARIES optimized ${MyLib_RELEASE_LIBRARY} debug ${MyLib_DEBUG_LIBRARY} ) ENDIF( WIN32 ) IF( UNIX ) FIND_LIBRARY( MyLib_LIBRARY MyLib ${MyLib_TOPLEVEL_DIR}/lib ) SET( MyLib_LIBRARIES "${MyLib_LIBRARY}" ) MARK_AS_ADVANCED( MyLib_LIBRARY ) ENDIF( UNIX ) # handle the QUIETLY and REQUIRED arguments INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(MyLib DEFAULT_MSG MyLib_LIBRARIES MyLib_INCLUDE_DIR) MARK_AS_ADVANCED( MyLib_INCLUDE_DIR ) </code></pre> <p>This build structure has worked for some test libraries I've built in the past, but I'm getting a link error when I try and use it to build a simple test app saying "error LNK1104: cannot open file 'libboost_thread-vc110-mt-s-1_54.lib'"</p> <p>I can get the test app to build and run successfully if I add it to the same project as the library build. I assume this is because the library build is finding the boost libs to link against, so it propagates through to the executables in the project.</p> <p>I built boost 1.54 with b2 link=static runtime-link=static threading=multi variant=debug,release --layout=tagged and linked both the library build and the test app build to the static MSVC runtime (/MT).</p> <p>Can anyone offer some help/advice/further tests with this one? I need to make sure that all the boost stuff is compiled-in to the API library, so our clients don't have to install boost themselves.</p> <p><strong>Additional Info</strong></p> <p>In-case it's helpful, here's the cmakelists.txt file from the library build:</p> <pre><code>set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib") set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) find_package(Boost REQUIRED COMPONENTS system date_time regex thread chrono) if(NOT WIN32) list(APPEND Boost_LIBRARIES pthread) endif() include_directories(${Boost_INCLUDE_DIRS}) FILE(GLOB srcs *.cpp) FILE(GLOB headers *.h) set(libname MyLib) set(deps ${Boost_LIBRARIES}) #To allow compilation. std=c++0x is for accepting the access to enums, which usually is just accepted with Visual Studio IF( NOT WIN32 ) set (CMAKE_CXX_FLAGS "-fpermissive -std=c++0x") ENDIF( NOT WIN32 ) SOURCE_GROUP( ${libname} FILES ${srcs} ) SOURCE_GROUP( "${libname}\\Hdr" FILES ${headers} ) add_library(${libname} ${srcs} ${headers}) target_link_libraries( ${libname} ${deps} ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload