I'm developing linux(ubuntu) c++ project from Visual Studio 2017. I want to integrate googletest into my code. I have installed googletest and run test example according following tutorial. Everything works fine when I run it from bash terminal using cmake.
Now I need to run it using VS. For that I need to specify path to /usr/lib/libgtest.a from VS. I added /usr/lib into Linker->General->Additional Library Directories and added libgtest.a into Linker->Input->Additional Dependencies. But compiler still cannot link the library:
g++: error: libgtest.a: No such file or directory
Try omit "lib" and ".a" from the file name as these portions of the filename seem to be added by the linker itself. In your case you would reference "gtest".
Try Configuration Properties -> Linker->Input->Library Dependencies with "gtest". Note: libgtest.a must in standard location so linker can search.
Related
I have been trying to build a cmake c++ project. More specifically I am trying to use the gdal library in this project. In the CMakeLists.txt it says find_library(GDAL gdal) after doing some research i found, that visual studio can open cmake files by default as mention in this thread: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019.
Moreover, visual studio should also automatically include the gdal library once i have set it up with vcpkg correctly. I've already downloaded the x64-windows version of the library (vcpkg install gdal:x64-windows) in order to build for the right architecture and made it available via vcpkg integrate install on a user-wide scope.
After some trial and error, everything works fine now, the toolchain gets included accordingly and the library is found automatically, resulting in a configuration like that:
However, when trying to include the header files (or anything else; see code snippet), visual studio does not seem to link the library correctly as it will result in the error message: cannot open source file "gdal/gdal.h".
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdal.h>
#include <gdal>
Where should I further investigate?
As others have said vcpkg integrate install and vcpkg.cmake don't work together the reason being:
set_target_properties(${name} PROPERTIES VS_USER_PROPS do_not_import_user.props)
set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false)
this deactivates the integration. The reason to deactivate the integration is so that you don't write an incomplete CMakeLists.txt (e.g. missing the include directory or not linking all required libraries).
As such replace find_library(GDAL gdal) with find_package(GDAL REQUIRED) and target_link_libraries against the target GDAL::GDAL (https://cmake.org/cmake/help/v3.17/module/FindGDAL.html)
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
Our team is stuck on a problem with connecting MongoDB CXX driver to QtCreator 5.10. We have builded and compiled mongo-c-driver and mongo-cxx-driver with CMake and msbuild (VS 2017 compiler). We created test project in Visual Studio added needed includes, libs, dependencies (also we copied dll files to debug folder) and it worked, we have connected to our MongoDB server. But as we were trying to add those libs to QtCreator project and run test project we got this kind of errors:
C:\Qt-projects\test_mongo\main.cpp:24: error: undefined reference to `_imp___ZN8mongocxx7v_noabi8instanceC1Ev'
We tried every combination of adding to .pro file these commands: LIBS += , INCLUDE_PATH +=. And we also tried to copy dll's to debug/release build folder.
The question is, how properly add all the includes, libs, dll's to .pro file, so the QT project could recognize MongoCXX driver?
P.S. we used this tutorial to create test project in VS2017:
Configuration Manager > Active Solution Platform: x64
C/C++ > Additional Include Directories: C:\mongo-c-driver\include\libbson-
1.0;C:\mongo-c-driver\include\libmongoc-1.0;C:\mongo-cxx-
driver\include\bsoncxx\v_noabi;C:\mongo-cxx-
driver\include\mongocxx\v_noabi;C:\Program Files\boost\boost_1_62_0;
Linker > Additional Library Directories: C:\mongo-cxx-driver\lib;
Linker > Input > Additional Dependencies: bsoncxx.lib;mongocxx.lib;
Build Events > Post-Build Event: COPY "C:\mongo-cxx-driver\bin\bsoncxx.dll"
"$(OutDir)";COPY "C:\mongo-cxx-driver\bin\mongocxx.dll" "$(OutDir)";COPY
"C:\mongo-c-driver\bin\libmongoc-1.0.dll" "$(OutDir)";COPY "C:\mongo-c-
driver\bin\libbson-1.0.dll" "$(OutDir)";
I'm currently trying to use the Dlib c++ library in my own project. So I included the main folder of dlib to my project. I also added the dlib/all/source.cpp to my project. When I try to compile the code of the svm_c_ex.cpp example in my own test.cpp file, I only get:
fatal error: dlib/svm.h: No such file or directory
The section Dlib: How to compile didn't help me and I couldn't find further information online. Any help is appreciated!
You need to compile the DLib library first, using the instructions from the website.
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake is a famous tool to build software on multiple platforms. It generates required files first and then you can compile the library using those generated files later.
You need to add the "include" directories (the folders where the headers exist) in your project configuration. I'm quite not sure of where exactly to add in Eclipse CDT.
After that, your program gives linker error because the the header files only contain skeletons of your library code. Actual implementation need to be linked with "linker options" in project properties. You need to add your library's .lib/.a files with your program. I don't exactly remember where is linker options in CDT (I'm talking in Visual Studio context)
Basically for any library you want to use in any C++ project:
You need to include HEADERS in your project properties
You need to link to actual implementation of the library. You can read about
static and dynamic libraries (Someone on SO must have given an
awesome explanation)
I'm trying to run some simple examples with Boost and I'm continuously running into this error and I have tried to compile this but I haven't been able to create "libboost_system-vc100-mt-gd-1_46_1.lib".
I keep ending up with this issue:
error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_46_1.lib'
Anyone encounter this error before? How do you compile this properly with NMAKE because it keeps telling me it's bulding "boost.regex without ICU / Unicode Support" which is giving it a "fatal error U1073 and tells me it doesn't know how to make "../src/c_regex_traits.cpp".
Sorry if this is a jumble it's just a lot of information that's getting more and more confusing to me.
Your boost is not properly built or installed. Please follow the instruction on how to install boost.
You need to build the boost libraries first.
To do this, open command line & go to boost root eg C:\dev\boost\1_46_1.
Depending on whether you want to build for 64bit or 32bit applications, type
(x64):bjam toolset=msvc address-model=64 variant=debug,release link=static threading=multi runtime-link=static,shared stage
(x86): bjam toolset=msvc variant=debug,release link=static threading=multi runtime-link=static,shared stage
to start compiling. Be patience while boost is building, it takes a lot of time. When building is complete you can find the library files in "stage\lib" folder.
Also note that you can delete the folder "bin.v2" once building is complete.
Now you need to point your VS2010 project to those libraries. Modifying part of mlimber's answer:
In VS2010, right-click on your project, select Properties and then go to Configuration Properties -> Linker -> General. Look for "Additional Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Another way to do this is the following
In VS2010, right-click on your project, select Properties and then go to Configuration Properties -> VC++ Directories. Look for "Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Apart from the above, one could also download from
http://sourceforge.net/projects/boost/files/boost-binaries/1.46.1/
the necessary libraries (including the file missing).
While trying to build Pion network library, I ran into a very similar problem since Pion has dependency on Boost library.
My Boost build was built using boostrap and bjam, and not BoostPro.
The error I got was this: LINK : fatal error LNK1104: cannot open file 'boost_thread-vc100-mt-gd-1_46_1.lib'
When I looked at C:\OpenSource\boost_1_46_1\stage\lib directory, I saw every file name started with libboost_ and not boost_. The file boost_thread-vc100-mt-gd-1_46_1.lib was clearly missing. That made me suspicious that not all boost libraries were built by bjam. After a little research, I reran bjam with the option --build-type=complete
Now I noticed that it started creating lib file names starting with boost_. Not to mention, Pion library could now compile successfully.
Hope this adds some clarity to this thread.
Or alternatively to ybungalobill's suggestion use the installer from www.boostpro.com.
In the installer you must just select the boost versions for msvc 10 and after installation update your visual studio include and lib directories in the VS2010 property sheets to point to the boost include and lib directory.
I take it that you used the BoostPro installer, but which library types did you install -- header only, static linking, DLLs, everything?
Assuming you did everything, then the problem is probably that you don't have the path to boost in your library paths. The problematic file name starts with "libboost" which tells me you're trying to use the statically linked version, which is fine. You should add the library path to your Makefile or project settings for all build configurations. It's probably something like C:\Program Files\Boost\boost_1_46_1 (for the newest version on a 32-bit version of Windows).
In VS2010, right-click on your project, select "All Configurations" at the top, then go to Configuration Properties | Linker [or Librarian if you're making a library] | General. Look for "Additional Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Do that for each project in the solution that uses Boost libraries that are not header-only.
For a Makefile, you'll have to locate the library paths and add Boost to it similarly but by hand.