I am trying to compile OpenCV3 and put it into Qt project because Qt officially provides MinGW Version, so I didn't use MinGW-w64.
I enabled ENABLE_CXX11 and disabled ENABLE_PRECOMPILED_HEADERS in CMake.
Now the problem is MinGW does not contain std::thread.
I know the mingw-std-threads lib can fix it. but I don't want to modify OpenCV source code. Is there any other way to adding c++ thread feature to MinGW? or tell OpenCV using pthread by CMake?
BTW. I don't want use Qt's MinGW because I think using official MinGW to compile the lib shall be used in any version of Qt.
Update:
In OpenCV detection_based_tracker.cpp, there is a CV_CXX11 Marco choice to the using std thread or the pthread. But I didn't see anywhere define CV_CXX11.
Is part of detection_based_tracker.cpp code:
#ifdef CV_CXX11
#define USE_STD_THREADS
#endif
#ifdef USE_STD_THREADS
#include <thread>
#include <mutex>
#include <condition_variable>
#else //USE_STD_THREADS
#include <pthread.h>
#endif //USE_STD_THREADS
My environment:
windows 7 64bit
cmake-3.10.1-win64-x64
opencv-3.4.0
gcc 6.3
What I tried:
install CMake and MinGW
disable ENABLE_PRECOMPILED_HEADERS in CMake-gui
comment #define USE_STD_THREADS in detection_based_tracker.cpp line 48
configure and generate Makefile
Run mingw32-make
it's successfully compiled, but I have to modify OpenCV source code.
If you use the right version of MinGW, namely MinGW-w64, most toolchains builds have the modern threading features available.
You can e.g. use the installer or install it through MSYS2.
Related
I am running clang-tidy checks using cmake version 3.20.0-rc1 on Windows 10.
My project builds using GNU 8.3.0.
Sadly I get the error
error: 'cstddef' file not found [clang-diagnostic-error]
#include <cstddef>
clang-tidy info:
LLVM (http://llvm.org/):
LLVM version 12.0.0
Optimized build.
Default target: i686-pc-windows-msvc
Host CPU: skylake
[clang-diagnostic-error] is basically a compiler error coming from the clang backend.
Clang-tidy needs an AST (abstract syntax tree) - your code has to be compileable by clang compiler in order to generate an AST. Only then will clang-tidy analyze your code.
Get your code to compile by clang instead of GCC and you should find the source of your problem.
I am starting in the world of LLVM and searched in several places and read several documentation about LLVM but I found nothing showing how to compile a program that uses LLVM headers and libs ....
I wrote this simple program just to try to compile, using the Visual Studio cross-compiler, I tried several command line options .... even using the -lLLVM option, but, nothing worked ...
I tried using g++ and clang++
#include <iostream>
#include <llvm/ADT/OwningPtr.h>
#include <llvm/Support/MemoryBuffer.h>
int main()
{
llvm::OwningPtr<llvm::MemoryBuffer> buffer
return 0;
}
When I try to build, I get this erro:
error : 'llvm/ADT/OwningPtr.h' file not found
So, what is the command line to compile this simple program?
The command llvm-config --cxxflags --ldflags --system-libs --libs core will provide you with all the linkable llvm libraries, provided you have llvm installed. Just link with this command in single quotes
I am trying to follow the modern cmake path and use the find_packages()/link libraries way.
I am using a test scenario in which:
LIB_B depends on LIB_A and EXEC_A depends on both.
I was wondering how you could link EXEC_A to the debug lib version of LIB_B and the release version of LIB_A or vice versa.
On LIB_A I am using set(CMAKE_DEBUG_POSTFIX "-debug") so my LIB_A is going to be LIB_A-debug when making the debug tree. I install them in /usr/local/lib and both reside there.
For example let's say I have this line of code in LIB_A:
#ifdef Release
printf("THIS IS RELEASE MODE");
#endif
This is going to differentiate LIB_A and LIB_A-debug.
in EXEC_A I would use
find_package(LIBA REQUIRED)
add_executable(EXEC_A main.cpp)
target_link_libraries(EXEC_A PUBLIC LIBS::LIBA LIBS::LIBB)
assuming I have exported the libraries in the LIBS namespace.
Is there any way to differentiate between library versions?
EDIT: I am on Linux (centos) and using GCC 8. My CMake version is 3.14
Sorry in advance for a kind-of-dumb question - I'm pretty new to all this.
So I downloaded asio from here, and tried to #include asio.hpp, but got the following error;
fatal error: boost/config.hpp: No such file or directory
I thought this was rather odd, as it was suppose to be independent of Boost. I poked around a bit, and saw that I needed to define ASIO_STANDALONE, which I promptly did, only to be met with more errors where it tried to #include something else from Boost.
Is there just a big list of all the things I have to #define to tell it to be standalone or something? That would be very helpful.
This is an old question, however i had the same problem currenlty with Visual Studio 2013 and Asio 1.10.6. In Visual there is no switch nor compiler flag for c++11 features. Even with #define ASIO_STANDALONEAsio requires Boost.
Solution is to manually specify that our compiler is c++11 compliant. Just add:
#define ASIO_STANDALONE
#define ASIO_HAS_STD_ADDRESSOF
#define ASIO_HAS_STD_ARRAY
#define ASIO_HAS_CSTDINT
#define ASIO_HAS_STD_SHARED_PTR
#define ASIO_HAS_STD_TYPE_TRAITS
#include <path_to_asio/asio.hpp>
As noted on the Asio website:
When using a C++11 compiler, most of Asio may now be used without a dependency on Boost header files or libraries. To use Asio in this way, define ASIO_STANDALONE on your compiler command line or as part of the project options.
Thus even when ASIO_STANDALONE is defined, Asio will use Boost when:
Using a non-C++11 compiler.
When using certain features, such as stackful coroutines that are based on the Boost.Coroutine library.
With asio-1.10.2, the following program:
#include <asio.hpp>
int main()
{
asio::io_service io_service;
}
compiles with gcc 4.8.1, using -DASIO_STANDALONE -std=c++11 compiler flags. Without specifying the compiler to use c++11, compilation fails when attempting to include Boost header files.
Is there a way to forcefully set the release mode of swig modules in cmake to build in release mode no matter what the actual build type is?
I am trying to build a python module using swig autogenerated code, and it complains of a python debug library when I build my application in debug mode.
I am not interested in debugging python module related code, so I am fine with not building the swig autogenerated python modules in debug mode.
Here is what I have in my cmakelists.txt file:
set_source_files_properties(abstract.i PROPERTIES CPLUSPLUS on)
swig_add_module(${PROJECT_NAME} python abstract.i)
swig_link_libraries(${PROJECT_NAME} ${PROJECT_NAME} ${PYTHON_LIBRARIES})
I suppose the real issue is that MSVC produces link error, due to the missing "python_d.lib"
Just insert into the header of SWIG interface (your *.i) files:
%begin %{
#ifdef _MSC_VER
#define SWIG_PYTHON_INTERPRETER_NO_DEBUG
#endif
%}
... and remove
#ifdef _MSC_VER
...
#endif
when the issue is generic, not MSVC related only
Hmm, how about wrapping your code snippet in
set(CMAKE_TMP_BUILD_TYPE ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE "Release")
and
set(CMAKE_BUILD_TYPE ${CMAKE_TMP_BUILD_TYPE})
?
You can tell CMake not to include a project in the default build of a certain configuration. For example, for a Python module (with the underscore added to the target by SWIG):
SET_TARGET_PROPERTIES(_${PROJECT_NAME} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_DEBUG True)