generate vs studio can not open boost library - c++

I have a cmake file that adds boost to a project.
the section that I add boost to project is as follow:
set(Boost_USE_STATIC_LIBS OFF)
set(BOOST_ROOT $ENV{BOOST_ROOT})
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib64-msvc-12.0)
find_package(Boost COMPONENTS thread system unit_test_framework filesystem REQUIRED)
and I add boost to my project in this way:
target_link_libraries(MyProject
${Boost_FILESYSTEM_LIBRARY})
When I compile my code, I am getting this error:
cannot open file 'libboost_filesystem-vc120-mt-gd-1_57.lib'
looking at project file, I can see that this library was added to project in correct way (input section of linker):
C:\Local\boost\lib64-msvc-12.0\boost_filesystem-vc120-mt-gd-1_57.lib
I have a similar setup on another computer which works perfectly. The difference between the two computer is:
working computer: windows 7 +VS 2012
not working computer Windows 8.1 + Visual Studio 2013.

Since libboost_filesystem-vc120-mt-gd-1_57.lib is obviously not the same as
boost_filesystem-vc120-mt-gd-1_57.lib you will have to either change the name in the generated project's properties or in cmake itself.

Related

Why doesn't visual studio find soundio.h?

I've been working with visual studio 19 and cmake. The initial objective is to link spdlog and libsoundio libraries to my project, to achieve it the following CMakeFile was created to compile my project.
cmake_minimum_required (VERSION 3.8)
set(APPNAME DrumHero)
project($APPNAME)
#C++ version
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(SOURCES src/drumhero.cpp)
set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/drumhero.h)
set(DEPENDENCIES_LIBS spdlogd libsoundio)
link_directories("C:/Program\ Files/libsoundio/lib" "C:/Program\ Files/spdlog/lib")
include_directories("C:/Program\ Files/libsoundio/include" "C:/Program\ Files/spdlog/include")
add_executable (${APPNAME} ${SOURCES} ${HEADERS})
target_link_libraries(${APPNAME}
PUBLIC ${DEPENDENCIES_LIBS})
set_target_properties(${APPNAME} PROPERTIES
PUBLIC_HEADER "${HEADERS}")
All libraries are installed and located in Program Files.
I copied the example program from libsoundio, but visual studio is showing some errors related to libsoundio, it seems that the library is not found by visualstudio, like the errors shown in the image below:
What it's most strange is that the code compiles, but when the .exe is executed the following message is shown:
Translation:
The execution of the code could not continue because libsoundio.dll was not found. Reinstalling the program to fix the problem.
Why is libsoundio not found?
If your code has sucessfully compiled, you have two options: Either copy the libsoundio.dll in the same folder as your .exe, or else, copy that DLL into a typical Windows path for DLLs, for example, C:\Windows\System32.
The first method should be easier if you want to deploy your application to another computer. That is the reason why Software for Windows is distributed as Installers, which create a folder in your machine and copy multiple files, sometimes DLLs, in the same path as the .EXE

Error : LNK1104 cannot open file 'pthread.lib'

I am trying to compile a native Linux C++ application in Windows using Visual Studio 2017. The app uses WebRtc's Acoustic Echo Cancellation(AEC) APIs to negate echo on wav files. Following is the CmakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
project(wav-aec)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_subdirectory(gflags)
add_definitions("-DWEBRTC_NS_FLOAT -DWEBRTC_WIN -DNOMINMAX")
#-DWEBRTC_UNTRUSTED_DELAY -DWEBRTC_LINUX -DWEBRTC_POSIX
include_directories(
webrtc
webrtc/webrtc/common_audio/signal_processing/include
webrtc/webrtc/modules/audio_coding/codecs/isac/main/include
)
set(WEBRTC_SRC_
base/buffer.cc
base/checks.cc
...
...
#system_wrappers/source/rw_lock_posix.cc
system_wrappers/source/trace_impl.cc
#system_wrappers/source/trace_posix.cc
)
function(prepend_path var prefix)
set(listVar "")
foreach(f ${ARGN})
list(APPEND listVar "${prefix}/${f}")
endforeach(f)
set(${var} "${listVar}" PARENT_SCOPE)
endfunction(prepend_path)
prepend_path(WEBRTC_SRC webrtc/webrtc ${WEBRTC_SRC_})
add_executable(webrtc-audioproc webrtc-audioproc.cpp ${WEBRTC_SRC})
target_link_libraries(webrtc-audioproc gflags pthread)
When I try to build it, I get the following errror:
Error : LNK1104 cannot open file 'pthread.lib'
Here is the link to the only linux dependent source file(cpp) of the project:
https://github.com/lschilli/wav-aec/blob/master/webrtc-audioproc.cpp
What will be the right approach to port the code from Linux to windows?
Whats is Windows equivalent of gflags and pthread? And what necessary changes needs to go to CmakeLists.txt?
P.S: I have already added pthread header, dll and libs to Visual Studio directory manually.
If 'missing pthread library' is the only error, you can use pthread-w32. We have successfully used it in some of our cross-platform apps requiring pthread.
They have libraries for both 64-bit and 32-bit. You can download and add it into your project. You haven't mentioned your toolset - their libraries are named differently depending on your toolset (MSVC or GNU) so you need to pick the right one. Check out their FAQ.
Hope it helps.
You need to us the actual lib file which is typically not "pthread.lib". It's most likely "pthreadVC3.lib" or "pthreadVC2.lib". Find the actual name by looking in the lib directory of your source package. You might see other lib files in there like "pthreadVCE3.lib" and "pthreadVSE3.lib", but you want to link "pthreadVC3.lib".
You can either add this in the project settings, or add the following code:
#pragma comment(lib,"pthreadVC3.lib")
To add it to the project settings:
Go to project properties->Configuration Properties->Linker->General and add your library path to Additional Library Directories
Go to project properties->Configuration Properties->Linker->Input and add the lib file (such as "pthreadVC3.lib") to Additional Dependencies
Make sure you have the correct version of pthread to match your compile settings, ie x86/x64.
In my case, I am using VCPkg for package management and I installed pthreads using the following commands:
vcpkg install pthread:x86-windows
vcpkg install pthread:x64-windows
And my package lib directory is "C:\vcpkg\installed\x64-windows\lib"
I additionally had to add the following to my project settings as vcpkg wasn't integrating automatically:
Go to project properties->Configuration Properties->VC++ Directories and add "C:\vcpkg\installed\x64-windows\include" to Include Directories
Go to project properties->Configuration Properties->VC++ Directories and add "C:\vcpkg\installed\x64-windows\lib" to Library Directories

Using boost::thread with CMake in MS Visual Studio 2017 results in two compiler errors

I want to use boost::thread in my project and I use CMake as a build tool. However, even a very simple setup results in two compiler errors:
main.cpp
#include <boost/thread.hpp>
int main()
{
boost::thread t;
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (ThreadTest)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.58.0 COMPONENTS random thread)
set(SOURCE_DIR src)
set(SOURCE_FILES
${SOURCE_DIR}/main.cpp
)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(test ${SOURCE_FILES})
target_link_libraries(test ${Boost_LIBRARIES})
endif()
I'm using Boost 1.68.0 which CMake can find and is able to build proper Visual Studio project files.
I tried using boost::random, and it worked.
However, compiling the above program results in two error messages:
E2512: Argument for a feature-test-macro has to be a simple identifier (pointing out to an error in boost file error_code.hpp)
LINK1104: File 'libboost_thread-vc141-mt-x64-1_68.lib' cannot be opened
This is the line in error_code.hpp which throws the error
I looked for the file 'libboost_thread-vc141-mt-x64-1_68.lib' in my boost installation but only found 'boost_1_68_0\lib64-msvc-14.0\boost_thread-vc140-mt-gd-x64-1_68.lib'
The linker settings contain the correct files:
So, my two questions:
Why is there a compilation error in error_code.hpp, which is part of the boost::system module and what can I do about it?
Why does VS want to link the file libboost_thread-vc141-mt-x64-1_68.lib, instead of the correct and available libboost_thread-vc140-mt-x64-1_68.lib?
I get the same error message in Visual Studio 2017 version 15.9 and Boost 1.69.0; I think that the trouble arises from this VS version introducing some version of __has_cpp_attribute which the boost authors expected only to be present in clang.
I had to change boost\system\detail\config.hpp line 50
from
#if defined(__has_cpp_attribute)
to
#if defined(__clang__) && defined(__has_cpp_attribute)
as the remaining preprocessor define is only relevant to clang anyways.
Changing boost headers is quite messy, but I didn't find a clean solution yet :(.
I was hoping /Zc had some switch to deactive this new "feature" (feature testing macro)
1) If you use
set(Boost_USE_STATIC_LIBS OFF)
and dont give a version number for boost
find_package(Boost COMPONENTS random thread)
since you are using 1.68 and not 1.58, right? It should work. I can reproduce your error messages with your settings and it works using the mentioned settings.
2) The boost CMake package file searches for a boost version depending on your selected compiler, I guess the default for vs 2017 is 14.1. See also here.
To solve this problem, download and install the proper prebuilt binaries.
Thank you for your hints!
The following steps resolved the problem:
1) I installed boost for MSVC 14.1 (prebuild binaries)
2) I added the following to the CMakeLists.txt:
add_definitions(-DBOOST_ALL_NO_LIB)

ITK: Can't find ITKCommon-x.xx.dll when executing HelloWorld Example

i successfully built ITK 4.13 (as 'Release') on Windows 10 with the latest Visual Studio version (Visual Studio 15 2017 Win64 compiler). Then i tried to built the ITKHelloWorld example using the following CMakeLists.txt (as shown in the example by ITK):
#CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HelloWorld)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(HelloWorld HelloWorld.cxx)
target_link_libraries(HelloWorld ${ITK_LIBRARIES})
Built runs without errors or warnings. Running the generated HelloWorld.exe file result in an ITKCommon-4.13.dll not found error.
The ITKCommon-4.13.dll was built by ITK, thus, i think i have to change something in the CMakeList file, but don't know what.
Any guess or solution?
Edit: The include(${ITK_USE_FILE}) expression in CMakeLists searches for UseITK.cmake, but this file is located in the source of ITK not in the build folder. Could this be a source of the error?
Edit2: Running a VTK Example also shows errors caused by not finding required .dlls.
There is no problem with your project. Windows can use dll libraries on runtime only if they are in PATH location. So there are two options: either you add bin/Release directory of ITK library to Windows's PATH system variable (the directory that contains all the ddls), or you just copy all the dlls from that directory to the one that contains your new application.
Precisely, you don't need to copy all the dlls, you can check by e.g. Dependency Walker, which ones are really needed.

Reference boost from CMake in CLion

CLion 1.2, with bundled CMake 3.3.2 and MinGW-w64 4.8.4
I'm trying to reference boost in CMakeLists.txt
set(BOOST_ROOT "O:/Project/lib/windows/boost_1_59_0")
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib)
set(BOOST_COMPONENTS_NEEDED filesystem )
find_package(Boost 1.59.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS_NEEDED})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
If there is no libraries needed, so I use
find_package(Boost 1.59.0)
boost is found and all works well.
But when I'm trying to reference libraries "Boost_FOUND" is not set
Boost libraries is built and there are following files in the O:/Project/lib/windows/boost_1_59_0/stage/lib folder
boost_filesystem-vc120-mt-1_59.dll
boost_filesystem-vc120-mt-1_59.lib
boost_filesystem-vc120-mt-gd-1_59.dll
boost_filesystem-vc120-mt-gd-1_59.lib
boost_system-vc120-mt-1_59.dll
boost_system-vc120-mt-1_59.lib
boost_system-vc120-mt-gd-1_59.dll
boost_system-vc120-mt-gd-1_59.lib
libboost_filesystem-vc120-mt-1_59.lib
libboost_filesystem-vc120-mt-gd-1_59.lib
libboost_filesystem-vc120-mt-s-1_59.lib
libboost_filesystem-vc120-mt-sgd-1_59.lib
libboost_filesystem-vc120-s-1_59.lib
libboost_filesystem-vc120-sgd-1_59.lib
libboost_system-vc120-mt-1_59.lib
libboost_system-vc120-mt-gd-1_59.lib
libboost_system-vc120-mt-s-1_59.lib
libboost_system-vc120-mt-sgd-1_59.lib
libboost_system-vc120-s-1_59.lib
libboost_system-vc120-sgd-1_59.lib
What I missed?
Probably because you want to build it your project with MinGW, but your libraries are compiled for Visual studio (you can see it from vc120 in libraries name).
You must build boost with MinGW-64 (you can use the same stage/lib folder because names are different).
Open the MinGW console and follow the same compilation step that you use for Visual Studio, but change toolset from msvc to gcc.