error in using cmake to build opencv3.2 - opencv3.0

I want to using the contrib part of opencv3.2, so i have to build it from sources. Here is my setting:
windows10, vs2013, cmake-gui-3.8.1.
after configuration in cmake-gui, i click the generator button, and i get the error message below. I am new to opencv, and i couldn't figure out how to solve it. Anyone who can help, THANKS.
CMake Error at E:/Program Files/opencv/opencv/source/opencv-3.2.0/cmake/OpenCVUtils.cmake:911 (add_library):
Cannot find source file:
E:/Program Files/opencv/opencv/build/modules/xfeatures2d/opencv_xfeatures2d_pch.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
E:/Program Files/opencv/opencv/source/opencv-3.2.0/cmake/OpenCVModule.cmake:784 (ocv_add_library)
E:/Program Files/opencv/opencv/source/opencv-3.2.0/cmake/OpenCVModule.cmake:729 (_ocv_create_module)
E:/Program Files/opencv/opencv/source/opencv-3.2.0/cmake/OpenCVModule.cmake:940 (ocv_create_module)
E:/Program Files/opencv/opencv/source/opencv_contrib-3.2.0/modules/xfeatures2d/CMakeLists.txt:2 (ocv_define_module)

I had the same issue with generating the opencv solution with contrib in cmake.
For me the solution was:
deleting the content of the build target folder,
restarting cmake
unchecking the 3 options: BUILD_opencv_world, ,ENABLE_PRECOMPILED_HEADERS
To be honest I don't know what is exactly going on but I'll try to give an educated guess.
The problem seems to be, that when trying to build the "world" modules of opencv and opencv_contrib precompiled headers are needed, which are missing in the source package of opencv_contrib. The indication for that is, that as soon as BUILD_opencv_contrib_world and BUILD_opencv_world are checked the option ENABLE_PRECOMPILED_HEADERS disappears. And obviously the precompiled headers (..._pch.cpp) are missing.

Related

No SOURCES given to target: MyProject ? (OpenSceneGraph Basics)

I am new to the CMake environment and I am trying to learn it for OpenSceneGraph. I am following the instructions from the book "OpenSceneGraph 3.0 Beginners Guide". I am getting an error when I try to create the "Hello World" project in Chapter 3.
When I drag the CMakeLists.txt to the cmake-gui, I always get an error;
CMake Error at CMakeLists.txt:12 (add_executable):
Cannot find source file:
main.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
.hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
CMake Error at CMakeLists.txt:12 (add_executable):
No SOURCES given to target: MyProject
According to the error I am getting, I need to specify the locations of the Sources but I could not get in which stage I need to do that.
I am struggling with the basics, and I need to learn these two programs for my thesis. I know the beginnings are hard to adjust, but I did not understand where I did a mistake. If anyone has faced the same problem, could you please help me?
Thank you for your help in advance.
P.S. I could provide more information regarding your answers, or questions.

cmake + qt + visual studio: moc objects on build

I am using cmake + qt + visual studio to work on a project. Problem I am having it that I would like visual studio to create new moc objects if I modify the QT ui files. If I just do a full build everything works file, but if I just modify something on the ui file it does not "auto moc" and I have to rebuild the whole project.
The cmake file I have is pretty simple:
cmake_minimum_required(VERSION 3.2)
set(CMAKE_VERBOSE_MAKEFILE ON)
project(main)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets)
file(GLOB CPP_FILES *.cpp)
add_executable(main ${CPP_FILES})
target_link_libraries(main Qt5::Widgets)
target_compile_features(main PUBLIC cxx_nullptr)
Does anyone know a way to get this to work (having visual studio to detect ui file modifications and "auto moc" the modified ui file)?
Start by replacing your file(GLOB ...) with explicitly listing out the files you want to include if you want proper dependency handling. This will also ensure the build is creating dependencies for the set of files you are expecting it to. This answer has more details about why you probably want to do this, aside from the reasons below.
The CMake documentation for AUTOUIC includes this statement:
If a preprocessor #include directive is found which matches
ui_<basename>.h, and a <basename>.ui file exists, then uic will be
executed to generate the appropriate file.
Can you confirm that your .cpp sources have #include directives that follow this pattern? In your file(GLOB ...) you are only capturing the .cpp files and not the .h files, so if you've only got the #include directives in the headers, AUTOUIC may not pick them up properly. It's been a while since I've used this and I can't recall if AUTOUIC would still find them if you only list the .cpp files and not the headers too in your add_executable() call, but it's something for you to try. You also may be facing a similar situation with AUTOMOC if you have headers which use the Q_OBJECT and Q_GADGET macros. So just explicitly list out your .cpp and .h files you give to add_executable() and see if that addresses your problem.

Include mingw libraries in compiled file

I am using cmake to generate a Eclipse CDT MinGW Project. (Eclipse Version Kepler)
This is my Cmakelist:
project(IMGTODICOM)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(IMGTODICOM IMGTODICOM.cxx)
target_link_libraries(IMGTODICOM ITKReview ${ITK_LIBRARIES})
The code compile and run without problem in my computer, but in other PC it does not run. Some dll like libgcc_s_dw2-1.dll are required. I looked for this dll in my computer and I found it in C:\MinGW\bin. To solve the problem I copied the content of this folder in the other PC and the exe file finally run.
However, I am wondering if there is a better method to run the exe file in any windows pc adding these libraries in the compilation process.
I was reading and I should make that the compiler link to a static library. In Eclipse I tried to add the dll under properties>C/C++ Include Path and Symbols and under project Path>Libraries, but it does not work. I tried to modify the CmakeList but it also does not work.
I don't know why this problem and how can I include the content of C:\MinGW\bin in the exe file.
Many Thanks for any help
Yes, there is a way. For pure C code:
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static")
For C++ code:
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")

code::blocks linking doesn't work for lib files

I just had a fresh new version of Code::Blocks(12.11) and tried to make a glut example project, but the generated code has some linking issues.
The minGW settings are is set to the correct values, since I successfully linked ad compiled a glfw project from *.a files. My problem is the linker just can't handle .lib files for some reason. I always get undefined reference errors, despite of the linking of the correct libraries.
I just don't know what to do/link...
How can I link *.lib files in the new Code::blocks?
IF I cannot, are there any glut binaries in the format of *.a files, or should I build it myself?
Finally I found this link, used this package, and did a clean build(rebuild) of the project, instead of Build. Works like a charm!

dev cpp win32 the program can't start because sqlite3.dll is missing

I am using dev c++ IDE which used ming gcc(i am not sure of it)
I wanted to use sqlite3 in my win32 c application
I downloaded sqlite3.dll and sqlite3.dev and used dlltool to create a .a file like libsqlite3.a and pasted in the lib folder of dev cpp and added this path in the project options -> parameters
i copied the header file sqlite3.h into the include folder(which i got from another website - http://www.opensource.apple.com/source/SQLite/SQLite-74/derived_source/sqlite3.h)
i executed the program and got the message 'the program can't start because sqlite3.dll is missing in your computer'
so i copied the sqlite3.dll into my working directory and then it worked
BUT
How to make the sqlite.* static while compiling?
I mean i thought by including the libsqlite3.a, the final exe will not be dependent of any external dll's.
So i want to know how to compile in a way that i will not be needing a dll and by doing so it makes my windows program standalone.
do i have a create a .lib file instead of .a file?
EDIT after answers and comments:
Besides, the devpak is working fine... yet i wanted to know how to include files to project or to create .a files so i am trying this way because if some components do not provide devpak then this will be the way we need to compile.. isn't it?
EDIT to show what i have done after the answer by CL and the two comments
This is how i have added the sqlite.c to project list
Here is the compile log
Compiler: Default compiler
Building Makefile:
"C:\Users\jayapalc\Documents\test-sqlite\Makefile.win"
Executing make...
make.exe -f "C:\Users\jayapalc\Documents\test-sqlite\Makefile.win" all
g++.exe -c sqlite3.c -o sqlite3.o -I"lib/gcc/mingw32/3.4.2/include"
-I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
sqlite3.c: In function `void strftimeFunc(sqlite3_context*, int,
sqlite3_value**)':
sqlite3.c:14727: error: invalid conversion from void*' tochar*'
The files i got in sqlite.org/sqlite-amalgamation-3071502.zip are
shell.c, sqlite3.h, sqlite3.c, sqlite3ext.h and i saw in other discussions that shell.c is not needed...
Besides, people were talking about gcc and g++... .
Apart from updating Dev-C++ itself, try this to compile sqlite.c as a C file:
Go to Project >> Project Options >> Files.
Find the C file we're talking about. Untick "Compile file as C++".
This should inform Dev-C++ that it should invoke gcc.exe, and not g++.exe.
If you don't want to compile sqlite yourself by adding it to your project, you can try passing the -static flag to GCC/G++ to force it to link libsqlite.a statically.
Just include the sqlite3.c file in your project.
You need only this filed, and it must be compiled as C, not C++.
Apparently, Dev-C++ does not allow mixing C and C++ source files in one project.
Instead, you could try to compile sqlite3.c as C and then include the generated .o file into the C++ project (on the Linker page).

Resources