OpenCV linking error by using `cv::cvtColor` - opencv

I am getting this error:
usr/bin/ld: CMakeFiles/stereo_img.dir/stereo_img.cpp.o: undefined reference to symbol '_ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii'
//usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
In my CmakeLists.txt I added:
add_definitions(-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_nonfree -lopencv_objdetect -lopencv_features2d )
I am using these includes:
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
I can use other types from opencv, such as cv::Mat.

Related

Problematic clang code generation with -O0

The following snippet:
#include <string>
#include <iostream>
int main()
{
std::string s = std::to_string(5);
std::cout << s << std::endl;
return 0;
}
Fails to link with Clang 3.6 on windows (accompanied with gcc 4.8.2 headers and libraries) when given the following options:
clang++ -std=c++11 -static -O0 bug.cpp
Please note that with -O2 the snippet compiles and links fine, so i suspect it may be some kind of clang bug.
EDIT 1:
I forgot to put the link error:
F:/Programs/LLVM/bin/../lib/gcc/i686-w64-mingw32/4.8.2\libstdc++.a(string-inst.o):(.text$_ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag[__ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag]+0x0): multiple definition of
`char* std::string::_S_construct<char*>(char*, char*, std::allocator<char> const&, std::forward_iterator_tag)'
C:\Users\THEART~1\AppData\Local\Temp\bug-b5df09.o:(.text[__ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag]+0x0): first defined here
F:/Programs/LLVM/bin/../lib/gcc/i686-w64-mingw32/4.8.2\libstdc++.a(string-inst.o):(.text$_ZNSsC2IPcEET_S1_RKSaIcE[__ZNSsC2IPcEET_S1_RKSaIcE]+0x0): multiple definition of `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char*>(char*, char*, std::allocator<char> const&)'
C:\Users\THEART~1\AppData\Local\Temp\bug-b5df09.o:(.text[__ZNSsC2IPcEET_S1_RKSaIcE]+0x0): first defined here
F:/Programs/LLVM/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: C:\Users\THEART~1\AppData\Local\Temp\bug-b5df09.o: bad reloc address 0x10 in section `.text[__ZSt9to_stringi]'
collect2.exe: error: ld returned 1 exit status
clang++.exe: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
EDIT 2:
I've been asked why i added the static flag in the compilation flags.
My purpose was to generate full static linked executables without the need of some gcc dlls (libstdc++6.dll libwinpthread.dll etc) so i have mostly been compiling with this command:
clang++ -std=c++11 -static -static-libstdc++ -static-libgcc -O0 bug.cpp
that i've been using with gcc too to generate full static executables.
After some experimenting i noticed that the combination of -static and -O0 flags is the problematic one so i omitted the others to not create any confusion.

Using xmlXPathDistinct in xmllib

I don't understand how to use xmlXPathDistinct for xmllib2
// xmlNodeSetPtr xmlXPathDistinct (xmlNodeSetPtr nodes)
xmlXPathObjectPtr result;
...
if(result) {
xmlNodeSetPtr nodeset = xmlXPathDistinct(result->nodesetval);
--> warning: initialization makes pointer from integer without a cast
Could someone provide me an example?
Riccardo
edit:
gcc -o test2 test2.c -L/usr/local/lib xml2-config --cflags --libs -lpthread -m64
Linux mymachine 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Ok, found. All these headers must be included
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/valid.h>
#include <libxml/hash.h>
#include <libxml/xmlerror.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
#include <libxml/uri.h>
#include <libxml/xpointer.h>

Simple CPP file failed to compile with Clang

#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Parse/ParseAST.h"
#include "clang/Rewrite/Rewriter.h"
#include "clang/Rewrite/Rewriters.h"
#include "llvm/Support/Host.h"
int main()
{
return 0;
}
I am compiling it as
clang++ -I/home/pc/llvm-3.3.src/tools/clang/include -I/home/pc/llvm-3.3-build/tools/clang/include -I/usr/local/include -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-uninitialized -Wnon-virtual-dtor -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -c -o simple.o simple.cpp
I am getting error as 'clang/Rewrite/Rewriter.h' file not found
About a year ago (before the release of llvm 3.2), ClangRewrite was split into 2 libraries: ClangRewriteCore and ClangRewriteFrontend.
This means that:
clang/Rewrite/Rewriter.h is now clang/Rewrite/Core/Rewriter.h.
clang/Rewrite/Rewriters.h is now clang/Rewrite/Frontend/Rewriters.h.
libclangRewrite.a is now libclangRewriteCore.a and libclangRewriteFrontend.a.
You can see the change in the LLVM repository here.

Compiling in OpenCV

Every time I try to compile this code in OpenCV, I keep getting this error. All I want to do is create a window:
//#include <iostream>
//#include <stdio.h>
#include "highgui.h"
int main() {
int cvNamedWindow(const char* name, int flags = CV_WINDOW_AUTOSIZE);
{
cvNamedWindow("sample");
}
cvDestroyWindow("sample");
}
However I'm getting this error:
window.cpp:4:21: fatal error: highgui.h: No such file or directory
I have checked in the necessary folder and highgui.h is very much installed.
Any help?
Include files as following
#include "opencv2/highgui/highgui.hpp"
And compile the file
g++ -ggdb `pkg-config --cflags opencv` filename `pkg-config --libs opencv`
If you have the OpenCV include as part of the include path, it should be
#include "opencv/highgui.h"
or
#include "opencv2/highgui/highgui.hpp"
depending on you using the c or c++

clang++ - Fatal error: 'bits/c++config.h' file not found

I'm using clang 2.9, compiled from source and when I try to compile a simple code like this:
#include <iostream>
int main (){
std::cout << "Hello\n";
}
I get the error:
/usr/include/c++/4.5/string:39:10: fatal error: 'bits/c++config.h' file not found
When I include /usr/include/c++/4.5/i686-linux-gnu, I get
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any ideas on how to solve this one?

Resources