imwrite throwing compile error in OpenCV - xcode

I have been using OpenCV for a while and also the imwrite function, but unfortunately this is not working any more.
I am running with OpenCV 2.4.3 with following sample code:
imwrite("somepath/somefile.png", myMat);
The error:
Undefined symbols for architecture x86_64:
"cv::imwrite(std::string const&, cv::_InputArray const&, std::__debug::vector<int, std::allocator<int> > const&)", referenced from:
MyProject::this_callback(int, void*) in MyProject.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The error looks somewhat familiar but i cannot determine whats wrong.

Yes, I've thought you were using XCode. I had the same problem. :)
If you change the project setup so that:
you use GNU++11 as C++ language dialect
libstdc++ (GNU C++ standard) as C++ standard library
your linking problem will go away.
I use Apple LLVM 4.1.
When I had this problem, I have tried just adding a new target to one of my old projects I knew, worked. Then I've just made that target a one-source-file program.
This must be a "magic" part of XCode as I think there was a time I could not get the same project working after a restart. :S

I did what Barnabas did and also got the issue on cvdef.h. I was getting desperate so and what I did was just changed the header file.
in /usr/local/cvdef.h line 205:
I changed
include <cstdint>
typedef std::uint32_t uint;
to:
include <tr1/cstdint>
typedef std::tr1::uint32_t uint;
based on this post
I think opencv devs should apply some changes to the code for 64bit..

use something like clang version 3.8.0 (trunk 257459), instead of gcc version 4.9.2 (MacPorts gcc49 4.9.2_1+universal) to compile
for reference, cmd: clang++ -std=c++11 `pkg-config --cflags --libs opencv` code.cpp -o code

Related

libssh symbols not found error gcc

I am trying to build a simple SSH client from Wil Allsopp's pen testing book. Working on Mac OS High Sierra with gcc-4.2 with libssh installed using Homebrew. The simplest version of the code is:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
my_ssh_session = ssh_new();
ssh_free(my_ssh_session);
return 0;
}
However a simple gcc build (gcc -Wall ssh_client.c) produces the following error:
Undefined symbols for architecture x86_64:
"_ssh_free", referenced from:
_main in ssh_client-aa8f09.o
"_ssh_new", referenced from:
_main in ssh_client-aa8f09.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
Can anyone explain these errors and how I can fix them?
Your build line doesn't appear to contain any include and linker flags. I imagine it is picking up the headers but not the library for ssh to link against. Have a look into pkgconfig for an easy way to maintain this.

OpenCV 3.0.0 with Xcode 6.3

I'm trying to compile a simple opencv code using Xcode but I'm getting a compilation error.
The opencv version is 3.0.0 and Xcode version is 6.3 (OS X 10.10.3)
In Xcode, Apple LLVM 6.1 Language C++ settings are:
c++ Language Dialect : C++11[-std=c++11]
c++ Standard Library : libc++
the error is:
Undefined symbols for architecture x86_64:
"cv::imread(cv::String const&, int)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I change the c++ standard library to libstdc++, then the error was:
/usr/local/include/opencv2/hal/defs.h:271:14: 'cstdint' file not found
Can someone show me how to get opencv work with Xcode? I've already followed lot of forums and guides but still getting the same error.
I had the same problem, either I got the "Undefined symbols x86_64" with libc++, or "cstdint file not found" with libstdc++.
What finally made it work for me was that I needed to add a lot more libs than I'm used to, it wasn't enough to add just core, imgproc, and highgui for even a simple project.
So I went to Build Settings, searched for Linking, and in Other Linker Flags I added the whole lot:
-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab
I'm using OpenCV 3.0.0 and Xcode 6.4. C++ Standard Library set to libc++ and C++ Language Dialect C++11. Hope this helps!

Undefined symbols with json spirit and Os X Mavericks

Since the recent update Mavericks, I have a problem linking with the library json_spirit.
I installed the new Command Line Tools, but I'm using gcc47 installed via macports. Json spirit (v4.06) has been compiled with the same gcc (after the update).
gcc (MacPorts gcc47 4.7.3_3) 4.7.3
I boiled it down to the following example :
test.cpp
#include <iostream>
#include "json_spirit_reader_template.h"
#include "json_spirit_writer_template.h"
#include "json_spirit_writer.h"
int main(int argc, char **argv) {
json_spirit::mValue a;
std::string s("[]");
json_spirit::read_string(s, a);
std::cout << json_spirit::write_formatted(a) << std::endl;
return 0;
}
which I compile with the following :
g++ -I/usr/local/include test.cpp -o test -L/usr/local/lib -ljson_spirit
And it gives this error :
Undefined symbols for architecture x86_64:
"json_spirit::write_formatted(json_spirit::Value_impl<json_spirit::Config_map<std::basic_strin g<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
_main in ccwUclng.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
And finally, using "nm -g /usr/local/lib/libjson_spirit.a | grep write_formatted" :
nm: no name list
0000000000000150 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE
000000000003afa8 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE.eh
0000000000000120 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE
000000000003af80 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE.eh
0000000000000270 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE
000000000003b118 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE.eh
0000000000000240 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE
000000000003b0c8 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE.eh
0000000000000090 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE
000000000003aeb0 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE.eh
0000000000000060 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE
000000000003ae88 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE.eh
0000000000000210 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE
000000000003b0a0 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE.eh
00000000000001e0 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE
000000000003b078 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE.eh
I don't know how to read the nm output, so I may be missing something obvious.
I've tried to install and uninstall every component (boost ..) one by one, compiling with the gcc from macports and / or the default, which is :
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Well, this is a half answer, because I never really got to explain exactly what happened, but I fixed it, so..
The answer was to rebuild boost from scratch, (icu as well) with the new system and the same compiler everywhere, for me it's gcc 4.7.3 installed with macports.
Also, I was trying to upgrade from boost 1.53 to boost 1.54, so it may have been part of the problem, but now anyway I went back to boost 1.53.

How to build qt 5 project on mac

I try to build a simple Qt 5 program on Mac. But I failed.
The code is very simple:
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication app (argc, argv);
return app.exec();
}
I used:
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib test.cpp
Then I got this error:
Undefined symbols for architecture x86_64:
"QApplication::exec()", referenced from:
_main in test-jPGORy.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in test-jPGORy.o
"QApplication::~QApplication()", referenced from:
_main in test-jPGORy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there anything i missing?
Firstly, don't compile and link Qt projects by hand; use qmake and project files.
Run qmake -project in your source directory to generate a basic project file.
Edit the project file and add the following line: QT += widgets
Now run qmake to generate a makefile.
Now run make to build your program.
Secondly, you can simply #include <QApplication>
If you want to use clang++ in favor of qmake, you need to specify libraries to link against to, along with the library directory (which you supplied).
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib -lQtCore -lQtGui test.cpp
I had the same problems and it seems to me that there is some sort of bug in the release it gave me some errors because out of a fresh install (using qt creator) i didn't have some obscure qt library (not the normal qt5 modules but some sort of library in development) so I tend to think that it could be qt's problem
That said I have some questions to better understand:
-are you using a IDE?
-if you are using one which is it?
-are you including all the modules in the *.pro for quake?
-have you used 4.8 version, did you experienced these problems with that?
P.S. if you do not have any particular necessity I suggest you to stick to version 4.8 for some time (as I am doing without problem) since 5.0 is just been released

Xcode 4 FLTK 1.3.0 undefined architecture x86_64

Hi, I am using Xcode 4 and trying to set up FLTK 1.3.0 to run Bjarne
Stroustrup's Chapter 12 FLTK Demo at the end of the chapter. I keep
getting the following error when compiling, and have no idea where to go.
I have an idea it might have to do with the linker flags, but I don't know
what flag to add and where...
Here's the error:
Undefined symbols for architecture x86_64:
"Fl_JPEG_Image::Fl_JPEG_Image(char const*)", referenced from:
Graph_lib::Image::Image(Point, String,
Graph_lib::Suffix::Encoding) in Graph.o
"Fl_GIF_Image::Fl_GIF_Image(char const*)", referenced from:
Graph_lib::Image::Image(Point, String,
Graph_lib::Suffix::Encoding) in Graph.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Are you passing the linker flags present with --use-images? try:
> fltk-config --use-images --ldflags
and check the results to make sure you're getting either the system image libs, or the ones optionally built with fltk.
I also found this to be quite useful:
fltk-config --compile test.cpp
It worked perfectly for me.
For more examples of using fltk-config check out http://www.fltk.org/doc-1.1/basics.html

Resources