First I wanted to modificate ffplay according to my requirments. Then I noticed that original ffplay from my build can't play some video files, but it didn't write any message to console. Then I noticed that ffmpeg also don't write any usage message when I run it without params. But it works. If I run it from terminal it's like running asynchronously! The terminal just shows next row. I mean it asks for a next command. But the ffmpeg process is visible in task manager and it writes the output video file what I had requested!
I created following souce file. I have modified the Makefile. So it have built the exe-file works just the same way. I have no idea how it can be.
#include <SDL.h>
#include "cmdutils.h"
const char program_name[] = "hello";
const int program_birth_year = 2013;
void show_help_default(const char *opt, const char *arg)
{
printf("zxcvbnm\n");
}
int main(int argc, char **argv)
{
printf("1234567890\n");
return 0;
}
And after that I created real hello world app with MinGW-w64 and qmake without eny extra libs. And its printf does not work.
I want to prevent this behavior.
I want to make printf working in traditional manner.
How I build FFmpeg:
PKG_CONFIG_PATH=/home/developer/workspace/MinGW32fs/lib/pkgconfig/ \
SDL_CONFIG=/home/developer/workspace/MinGW32fs/bin/sdl-config \
./configure \
--prefix=/home/developer/workspace/MinGW32fs \
--extra-ldflags="-L/home/developer/workspace/MinGW32fs/lib" \
--extra-cflags="-I/home/developer/workspace/MinGW32fs/include" \
--arch=x86 --target-os=mingw32 --cross-prefix=i686-w64-mingw32- \
--pkg-config=pkg-config --enable-libtheora --enable-libvorbis --enable-libvpx \
--enable-outdev=sdl --enable-shared --disable-static \
--disable-doc --disable-manpages --disable-podpages
make
Solved!
By some reason you must visibly specify you make console app.
In qmake helloworld:
CONFIG += console
In FFmpeg's configure script it's an extra-ldflag console:
PKG_CONFIG_PATH=/home/developer/workspace/MinGW32fs/lib/pkgconfig/ \
SDL_CONFIG=/home/developer/workspace/MinGW32fs/bin/sdl-config \
./configure \
--prefix=/home/developer/workspace/MinGW32fs \
--extra-ldflags="-L/home/developer/workspace/MinGW32fs/lib -Wl,-subsystem,console" \
--extra-cflags="-I/home/developer/workspace/MinGW32fs/include" \
--arch=x86 --target-os=mingw32 --cross-prefix=i686-w64-mingw32- \
--pkg-config=pkg-config --enable-libtheora --enable-libvorbis --enable-libvpx \
--enable-outdev=sdl --enable-shared --disable-static \
--disable-doc --disable-manpages --disable-podpages
Related
I'm trying to build cc-tool debugger as described here https://www.zigbee2mqtt.io/information/flashing_the_cc2531.html
But at configure step got this error
checking for the Boost regex library... no
configure: error: cannot find the flags to link with Boost regex
Same issue described here https://github.com/dashesy/cc-tool/issues/25 and suggested solution is to downgrade boost to 1.60. But it does not work anymore because 1.60 deleted from brew.
I've tried to use clang compiler instead of gcc but it does not work too.
MacOS: Big sur 11.5.2 (20G95)
Here the solution:
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/usr/local/include \
LDFLAGS=-I/usr/local/include \
./bootstrap
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/usr/local/include \
CXXFLAGS="-std=c++0x" \
LDFLAGS="-I/usr/local/include -lboost_system" \
LIBUSB_CFLAGS=-I/usr/local/include/libusb-1.0 \
LIBUSB_LIBS="-L/usr/local/lib -lusb-1.0" \
./configure
It allows to configure with boost 1.76. Found here https://gist.github.com/kidpixo/ef1a26ae953e3939a4eebe1b6fd2f07c
For mac with M1 CPU, macOS Monterey (boost version 1.78.0):
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/opt/homebrew/include \
LDFLAGS=-I/opt/homebrew/include \
./bootstrap
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
CPPFLAGS=-I/opt/homebrew/include \
CXXFLAGS="-std=c++0x" \
LDFLAGS="-L/opt/homebrew/Cellar/boost/1.78.0_1/lib/" \
LIBUSB_CFLAGS=-I/opt/homebrew/include/libusb-1.0 \
LIBUSB_LIBS="-L/opt/homebrew/lib -lusb-1.0" \
./configure
I've hit the very same issue, right today (same OS: MacOS 11.5.2).
I think one solution would be to create your own tap, with the Formula copied from the removed boost#1.60 (Homebrew/homebrew-core#84434).
I was reading this article on how to create compact builds for applications using OpenCV.
But, this article includes only GCC related optimizations. I am looking for equivalent options in Visual Studio, but am able to find only the option to minimize size (/Os) and the option /LTCG.
I am building a very simple OpenCV console application (code is below) using OpenCV static libraries built from source. The issue is the size of executable is too large (37 MB in Debug build and 19 MB in Release build). I want to reduce that size to a few MBs and I am looking for ways to do that - I found that article while researching about this.
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
int main()
{
cv::Mat m = cv::imread("sample.jpg");
cv::imwrite("output.jpg", m);
std::cout << "Hello World!\n" << m.rows << " " << m.cols;
return 0;
}
Just in case anyone wants to know, I am including following libraries (the below are for Release mode):
opencv_core430.lib
opencv_imgproc430.lib
opencv_imgcodecs430.lib
libjpeg-turbo.lib
libpng.lib
libtiff.lib
libwebp.lib
ippiw.lib
zlib.lib
IlmImf.lib
libjasper.lib
ittnotify.lib
ippicvmt.lib
If anyone has any ideas what equivalent options are in Visual Studio, it would be of great help.
Also, is there anyone who was successful to reduce the executable size using static OpenCV libraries on Visual Studio?
I encountered the same issue and I found two things which make a big difference: performance libraries/frameworks and unnecessary file types.
Since you are building from source, you should be able to use cmake-gui to adjust the configuration to disable these:
WITH_IPP
WITH_ITT
WITH_OPENCL
Then, disable these additional image types if you need only JPG:
WITH_JASPER
WITH_PNG
WITH_OPENJPEG
WITH_WEBP
WITH_TIFF
WITH_OPENEXR
WITH_IMGCODEC_HDR
WITH_IMGCODEC_SUNRASTER
WITH_IMGCODEC_PXM
WITH_IMGCODEC_PFM
Since imread and imwrite determine the file type based on the given string, the linker has no way of knowing that the code for the other unnecessary image formats can be removed.
When I apply these changes and compile your program using Visual Studio 2022 it comes out to about 1.7 MB in release mode. (Starting with the default configuration and disabling only BUILD_SHARED_LIBS, I had seen the same 19 MB executable that you had reported.)
You can build as per your modules requirements, details in the blog.
The simplest way to build is using OpenCV cmake example:
cmake
-D WITH_CUDA=OFF \
-D WITH_MATLAB=OFF \
-D BUILD_ANDROID_EXAMPLES=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_opencv_objdetect=OFF \
-D BUILD_opencv_video=OFF \
-D BUILD_opencv_videoio=OFF \
-D BUILD_opencv_features2d=OFF \
-D BUILD_opencv_flann=OFF \
-D BUILD_opencv_ml=OFF \
-D BUILD_opencv_photo=OFF \
-D BUILD_opencv_python=OFF \
-D BUILD_opencv_shape=OFF \
-D BUILD_opencv_stitching=OFF \
-D BUILD_opencv_superres=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_opencv_videostab=OFF \
-D BUILD_opencv_highgui=ON \
-D BUILD_opencv_imgproc=ON \
..
For static linking, you can pick and choice the module(s) by un-archiving .a to .o and bundle them in single .a.
CAUTION: be very sure that you do not break the dependencies.
Example:
to unarchive a .a using ar -x libopencv_imgproc.a and to archive again
ar -rc libopencv_custom.a *.o
I want to know how much my code is faster with CUDA, so I compile OpenCV with below switches (including cuda)
cmake CMAKE_BUILD_TYPE=RELEASE \
CMAKE_INSTALL_PREFIX=/usr/local \
WITH_CUDA=ON \
ENABLE_FAST_MATH=1 \
CUDA_FAST_MATH=1 \
WITH_CUBLAS=1 \
INSTALL_PYTHON_EXAMPLES=OFF \
OPENCV_EXTRA_MODULES_PATH=/home/saeed/opencv_contrib/modules \
BUILD_EXAMPLES=OFF ..
and I'm working on Linux based machine and with dedicated GPU on my system so how I can measure gpu usage for opencv code? I did that with using
$ nvidia-smi
command,which give me general information about gpu usage and etc (in bash) .
for trace this output I use
$ watch -n 0.1 nvidia-smi
command,which updates informations every 0.1 second(0.1 second is minimum)
So I have a code like below in opencv(You can see I don't use any cuda function in it)
#include "opencv2/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
int main()
{
cv::Mat src(1500,1500,CV_8UC3),res;
for (int var = 0; var < 70; ++var)
{
Canny(src,res,50,150,5);
}
}
So when i run above code I take a screen shot in my nvidia-smi page(to know how much gpu ram is in use)
As you can see there is 23 MiB is in use !!! so why this happen !!if it is normal how we could stop that !? How to stop GPU for this problem
You can make the CUDA runtime indicate that there are no available GPUs with the following environment variable:
CUDA_VISIBLE_DEVICES="" ./my_opencv_code_that_wont_use_gpu
If you want OpenCV to actually not do anything with the GPU, my best guess would be to compile it without CUDA support:
cmake CMAKE_BUILD_TYPE=RELEASE \
CMAKE_INSTALL_PREFIX=/usr/local \
WITH_CUDA=ON \ ********MODIFY
ENABLE_FAST_MATH=1 \
CUDA_FAST_MATH=1 \ ********MODIFY
WITH_CUBLAS=1 \ ********MODIFY
INSTALL_PYTHON_EXAMPLES=OFF \
OPENCV_EXTRA_MODULES_PATH=/home/saeed/opencv_contrib/modules \
BUILD_EXAMPLES=OFF ..
I have been able to successfully integrate opencv with Qt using the following tutorial:
How to link opencv in QtCreator and use Qt library
However, When I try to write line #include "opencv/cv.h in my .cpp file, qt throws me an error:
D:\opencv\opencv_bin\install\include\opencv2\flann\saving.h:113: error: exception handling disabled, use -fexceptions to enable
throw FLANNException("Invalid index file, cannot read");
^
I am not sure if this is a qt problem or an opencv installation problem.
TEMPLATE = app
TARGET = cube4
QT += 3d
SOURCES = cubeview.cpp main.cpp \
haptics.cpp
HEADERS = cubeview.h \
haptics.h \
src/haptics.h \
src/adll.h \
src/afuncs.h \
src/atypes.h \
src/avars.h \
src/glut.h \
src/StdAfx.h \
hdl/hdl.h \
hdl/hdlConstants.h \
hdl/hdlErrors.h \
hdl/hdlExports.h \
hdlu/hdlu.h \
hdlu/hdluExports.h
HEADERS += \
Widget.h
RESOURCES = cube.qrc
win32:LIBS += -LD:\\opencv\\opencv_bin\\bin \
libopencv_core248d \
libopencv_highgui248d \
libopencv_imgproc248d \
libopencv_features2d248d \
libopencv_calib3d248d \
win32: INCLUDEPATH +="D:/opencv/opencv_bin/install/include"
Thanks iHarob. The solution was to add "exceptions" to the CONFIG variable in your project file (the *.pro file):
CONFIG += exceptions
This takes care of passing the correct compiler flags. The answer can be found here:
How to enable exception handling in mingw
I've successfully powered my way through the WDK XPSDrv sample project and modified it to do what I need. However, I absolutely cannot figure out how to get the build scripts to reference/include/whatever shell32.lib. I'm a .NET guy! This is strange and terrifying territory.
I think adding a dependency reference is what I need to do. When I compile I get this error
3>errors in directory c:\winddk\7600.16385.1\src\printgit\xpsdrvsmpl\
src\filters\common
3>c:\winddk\7600.16385.1\src\printgit\xpsdrvsmpl\src\filters\common\
xdstrmflt.cpp(238) : error C3861: 'ShellExecute': identifier not found
Due to my extreme lack of knowledge (and hurry) I'm not using visual studio, just simple mods in notepad++ and the shell wdk build environment. I have a surrogate project in VS where I've been writing and testing small chunks of code. In that project I added a Dependency library to shell32.lib and everything worked perfectly.
There's a makefile that references a sources, the contents are below.
Not that it matters, but the code that requires shell32 is
HINSTANCE statu = ShellExecute(NULL,TEXT("open"),szTempFileName,NULL,NULL,9);
Here's the sources file.
INCLUDES=$(INCLUDES); \
.\; \
.\..\inc; \
.\..\debug; \
$(DDK_INC_PATH); \
$(SDK_INC_PATH)\gdiplus; \
USE_ATL=1
USE_STL=1
ATL_VER=70
STL_VER=70
# We use STL 7.0, which is not available pre-Vista. We therefore set USE_LIBCMT=1
# If STL 7.0 is not necessary, USE_MSVCRT=1 is recommended
USE_LIBCMT=1
USE_IDLBASED_DLLDATA=1
USE_OBJECT_ROOT=1
MSC_WARNING_LEVEL=/W4 /WX
USE_NATIVE_EH=1
PRECOMPILED_CXX=1
PRECOMPILED_INCLUDE=precomp.h
# To remove debug code remove -DDBG from the line below
C_DEFINES=$(C_DEFINES) -D_UNICODE -DUNICODE
SOURCES=\
bkpchndlr.cpp \
bkpthndlr.cpp \
bkschema.cpp \
cmpthndlr.cpp \
cmprofpthndlr.cpp \
cmprofpchndlr.cpp \
cmintpthndlr.cpp \
cmschema.cpp \
cmprofileschema.cpp \
cmintentsschema.cpp \
globals.cpp \
nupschema.cpp \
nupchndlr.cpp \
nupthndlr.cpp \
pchndlr.cpp \
pgscpchndlr.cpp \
pgscpthndlr.cpp \
pgscschema.cpp \
porientpthndlr.cpp \
porientschema.cpp \
psizepthndlr.cpp \
psizeschema.cpp \
pimagepthndlr.cpp \
pimageschema.cpp \
pshndlr.cpp \
pthndlr.cpp \
ptquerybld.cpp \
schema.cpp \
wmpchndlr.cpp \
wmpthndlr.cpp \
wmschema.cpp \
workbuff.cpp
TARGETNAME=xdsmplcmn
TARGETTYPE=LIBRARY
For example in your sources file:
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib $(SDK_LIB_PATH)\user32.lib $(SDK_LIB_PATH)\shell32.lib
... amend as needed ;)
However, your error is actually not a linker error but a compiler error, so you'll likely want to include the header that declares ShellExecute, which is shellapi.h, in some way.
Just looked the sample up in my WDK (7600.16385.1) and as a matter of fact you removed the very important part reproduced below, to which you just would have to append the other .lib files to link against:
TARGETLIBS= \
$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib \
$(SDK_LIB_PATH)\winspool.lib \
$(SDK_LIB_PATH)\ole32.lib \
$(SDK_LIB_PATH)\oleaut32.lib \
$(SDK_LIB_PATH)\advapi32.lib \
$(SDK_LIB_PATH)\msxml6.lib \
$(SDK_LIB_PATH)\uuid.lib \
$(SDK_LIB_PATH)\Comdlg32.lib \
$(OBJ_PATH)\..\debug\$O\xdsdbg.lib \
$(OBJ_PATH)\..\common\$O\xdsmplcmn.lib \
... apologies, there are plenty of sources files as part of this sample, so of course I cannot really know which of the samples you modified and are trying to build :)