Running OpenCV 3 in Mac Terminal - c++

For the past week, I have been trying to run some simple OpenCV programs using the terminal. I have tried many tutorials and recommendations from various forums with little success. The problem arises when trying to link the OpenCV header files to my OpenCV main program. For a simple c++ program I would simply execute g++ main.cpp header.hpp to generate the program executeable. How do I go about linking the necessary OpenCV header files such as <opencv2/highgui/highgui.hpp> & <opencv2/core/core.hpp>?
For example, when attempted to execute the sample program from http://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html the following occurs:
Desktop Robert$ g++ loadIMG.cpp
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in loadIMG-54c517.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in loadIMG-54c517.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::operator=(cv::Mat const&) in loadIMG-54c517.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in loadIMG-54c517.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in loadIMG-54c517.o
"cv::imread(cv::String const&, int)", referenced from:
_main in loadIMG-54c517.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in loadIMG-54c517.o
"cv::waitKey(int)", referenced from:
_main in loadIMG-54c517.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in loadIMG-54c517.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please note: OpenCV has already been built using the following tutorial: http://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/
Any help or direction would be appreciated. Thank you.

You haven't specified:
the include path (header search path) using -I"/path/to/your/include"
the path to the libraries using -L"/path/to/libraries"
which libraries to link against, in this case core and highgui: -lopencv_core -lopencv_highgui
I have opencv headers in /opt/local/include and libraries in /opt/local/lib,
so to compile a basic program like this:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
Mat src = Mat(Size(320,240),CV_64F);;
namedWindow("test");
cout << "press any key to close" << endl;
while(true){
randn(src,0,1.0);
imshow("test",src);
if(waitKey() > 0) break;
}
}
I compiled like so:
g++ main.cpp -I"/opt/local/include/" -L"/opt/local/lib/" -lopencv_core -lopencv_highgui -o main
Then ran ./main:
Bare in mind you might have opencv installed in the /usr/local folder not /opt/local depending how you compiled/installed OpenCV.
Also, you might have pkg-config installed which can come in handy when you need to link against more libraries.
For example, you can run:
pkg-config --libs --cflags opencv
which in my case outputs:
-I/opt/local/include/opencv -I/opt/local/include -L/opt/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
but in your case, it should output your particular OpenCV paths.
This would simplify compiling to this:
g++ main.cpp `pkg-config --libs --cflags opencv` -o main
The guide you linked to uses cmake which generates Makefiles for you.
That's another nice options. Also, based on the same guide, you should have XCode installed which you can use to create a Command Line Tool and point the Header Search Paths and Library Search Paths.

I create a similar file that maybe can help you.
First I use:
sudo brew install opencv
Then I install the opencv.3.0 according to the hint given by the terminal. Then in the .cpp file which needs the API from opencv, I use:
#include "opencv2/opencv.hpp"
As my only include file about opencv. Actually, at that project I use highgui, core, and imgprog. But no worries here, I will show you how to solve them in linking part.
After you finish your project, you are going to compile your project on the terminal.
Because I also used the JNI interface, so I still need to link the jni.h.
Here we go:
g++ xxxx.cpp xxx.cpp -lstdc++ -fPIC -shared (to create a shared object)
-I/absolute path/ (we can use -I to be followed with the absolute path of the library you need to use )
-I/Users/yuanzhan/Downloads/OpenCV-2.0.0/src/
-I /Users/yuanzhan/Downloads/OpenCV-2.0.0/include/opencv/ -I/usr/local/Cellar/opencv3/3.1.0_3/lib -lopencv_core (open the library for use if you use the API fro here)-lopencv_highgui -lopencv_imgproc -L.(i put the cv2. on local otherwise you can add the absolute path here) -lcv2(use the package) -v -o libopenCvSDK.so(generate my .so package).

Related

cpprestsdk: Undefined symbols for architecture x86_64

I have visited all the other questions but from what I see none are my issue.
Running OS X El Capitan 10.11.6 on MacBook Pro 16GB memory Intel Core I7
I have ran brew doctor as well but don't see any issues that would cause this issue. Below is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.0.0)
project(WebClient VERSION 0.0.0)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPLIER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPLIER_SUPPORTS_CXX0X)
if(COMPLIER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support.
Please use a different C++ compiler.")
endif()
FIND_PACKAGE( Boost 1.62 COMPONENTS program_options REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
set(OPT_CPPFLAGS "-I/usr/local/opt/openssl/include -I/usr/local/opt/libiconv/include")
set(OPT_LDFLAGS "-v -lcpprest -lboost_system -L/usr/local/opt/openssl/lib -L/usr/local/opt/libiconv/lib -lcrypto -lssl")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPT_CPPFLAGS} -v -g -O3 -fno-common -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPT_LDFLAGS}")
add_executable(anyExecutable webclient.cpp)
TARGET_LINK_LIBRARIES( anyExecutable ${Boost_LIBRARIES} )
include(CPack)
I used brew to install cpprestsdk/2.8.0 which also includes boost/1.62.0 and openssl/1.0.2j and libiconv/1.14. My code is from a tutorial on wiki cpprestsdk.
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <atomic>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main(int argc, char* argv[]) {
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream( U("results.xml") ).then(
[=](ostream outFile) {
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.dictionaryapi.com/api/v1/references/"));
// Build request URI and start the request.
uri_builder builder(U("thesaurus/xml/"));
builder.append_path(U("ranking"),true);
builder.append_query(U("?key"), U("--------------------"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then( [=](http_response response ) {
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then( [=](size_t ) {
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try {
requestTask.wait();
} catch (const std::exception &e) {
printf("Error exception:%s\n", e.what());
}//try-catch BLOCK
return 0;
}//Main
To save some space only printing some the errors they all the same in can't be found:
[vscode] Executing cmake command: cmake --build /Users/gumpy/git-repos/webapi/build --target all --config Debug -- -j 10
[ 50%] Building CXX object CMakeFiles/anyExecutable.dir/webclient.cpp.o
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name webclient.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 274.1 -v -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -coverage-file /Users/gumpy/git-repos/webapi/build/CMakeFiles/anyExecutable.dir/webclient.cpp.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -I /usr/local/include -I /usr/local/opt/openssl/include -I /usr/local/opt/libiconv/include -stdlib=libc++ -O3 -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /Users/gumpy/git-repos/webapi/build -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o CMakeFiles/anyExecutable.dir/webclient.cpp.o -x c++ /Users/gumpy/git-repos/webapi/webclient.cpp
clang -cc1 version 8.0.0 (clang-800.0.38) default target x86_64-apple-darwin15.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/usr/local/opt/openssl/include
/usr/local/opt/libiconv/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
[100%] Linking CXX executable anyExecutable
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o anyExecutable -L/usr/local/opt/openssl/lib -L/usr/local/opt/libiconv/lib -search_paths_first -headerpad_max_install_names -lcpprest -lboost_system -lcrypto -lssl CMakeFiles/anyExecutable.dir/webclient.cpp.o /usr/local/lib/libboost_program_options-mt.dylib -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in webclient.cpp.o
boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&, timespec const&) in webclient.cpp.o
"boost::chrono::steady_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::chrono::system_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*) in webclient.cpp.o
ld: symbol(s) not found for architecture x86_64
The missing symbol names was due to a missing library. The necessary CPPFLAGS and LDFLAGS are:
CPPFLAGS = -stdlib=libc++
LDFLAGS = -lcpprest -lboost_system -lboost_thread-mt -lboost_chrono-mt -lssl -lcrypto
Thanks so much for everyone's help.
Original Question:
"web::uri_builder::append_path(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
std::__1::__function::__func<main::$_0, std::__1::allocator<main::$_0>, pplx::task<web::http::http_response> (Concurrency::streams::basic_ostream<unsigned char>)>::operator()(Concurrency::streams::basic_ostream<unsigned char>&&) in webclient.cpp.o
"web::uri_builder::append_query(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
web::uri_builder& web::uri_builder::append_query<char [37]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [37], bool) in webclient.cpp.o
"web::uri_builder::to_string()", referenced from:
std::__1::__function::__func<main::$_0, std::__1::allocator<main::$_0>, pplx::task<web::http::http_response> (Concurrency::streams::basic_ostream<unsigned char>)>::operator()(Concurrency::streams::basic_ostream<unsigned char>&&) in webclient.cpp.o
"web::uri::encode_impl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<bool (int)> const&)", referenced from:
web::uri_builder& web::uri_builder::append_query<char [37]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [37], bool) in webclient.cpp.o
...
The ::__1 is LLVM's anonymous namespace. What you see above is a symptom of mixing and matching runtimes. I.e., inconsistent use of -stdlib=XXX.
You need to build everything with GNU's gear and -stlib=libstdc++; or you need to build everything with LLVM's gear and -stdlib=libc++.
What I found works best to avoid user problems and questions is to always use LLVM's gear on OS X and iOS. I.e., always use -stdlib=libc++.
Updated Question:
Undefined symbols for architecture x86_64:
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in webclient.cpp.o
boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&, timespec const&) in webclient.cpp.o
"boost::chrono::steady_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::chrono::system_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*) in webclient.cpp.o
ld: symbol(s) not found for architecture x86_64
For the updated question, see Using and building the library in the Boost user guide. You have to build Boost with threading support (does Brew do that?), and you have to link to the Boost threading library (is CMake doing that?).
I don't use Boost or CMake, so I can't take you any further. Sorry about that.
set(OPT_CPPFLAGS "-I/usr/local/opt/openssl/include -I/usr/local/opt/libiconv/include")
I'm no CMake expert, but this could be problematic, too. CPPFLAGS is the flags for the C preprocessor. They may or may not be added to the CFLAGS and CXXFLAGS.
You should definitely call-out the same flags for CFLAGS and CXXFLAGS just in case. If this were an Autotools project, then I would change the should to a must. But like I said, I'm no CMake expert by any strecth of the imagination.
And one final note... You can't use CMake to build OpenSSL. You have to configure an build it yourself. Once installed, you can reference the installed OpenSSL in a find-openssl.cmake type fashion.
The reasons are not readily apprent... OpenSSL's Configure script sets up some important settings that are used later in the build process. The two most important files for the settings are <opensslconf.h> and <bn.h>.
You can also get an impressive speed improvement (2x to 4x) for Diffie-Hellman and Elliptic Curves on Intel-based x86_64 machines by Configureing with enable-ec_nistp_64_gcc_128.
It looks like this may be the same issue you have, with the answer being link against -lcrypto.
Edit: Your problem is that you're trying to build a program that needs to be linked against other "libraries" - that is, other pieces of code that are usually pre-compiled - that are somewhere on your system, and which define "symbols," which is basically another way of saying variables or function names.
You let the compiler know which libraries you need by including arguments to the compile command that signify what you need to be linked with - in this case, your first few issues went away because you linked with -lcrypto, and from then on your code was able to find the 'symbols' - that is, variables and function names - that were previously 'undefined.'
For the rest of your issues, where you added 'lcrypto,' try using the arguments from this wiki on building cpprestsdk on Linux. The flags appear to be:
-lboost_system -lssl -lcpprest -lboost_chrono
Last, but not least, have you follow the instructions for building this software on mac OSX on their site? It might save you a lot of pain! :)
Edit: added a few more.

What is the darwinssl library location on Mac OS X?

I am trying to compile curl and statically link it to another project.
I did manage to compile it for my mac architecture(x86_64) and got "libcurl.a".
Now when I try to build:
#include <curl/curl.h>
int main()
{
CURL *curl = curl_easy_init();
}
with g++ tornado.cc -o tornado (path-to-where-it-is)libcurl.a -std=c++11
I get:
Undefined symbols for architecture x86_64:
"_CFArrayAppendValue", referenced from:
_append_cert_to_array in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayCreate", referenced from:
_darwinssl_connect_common in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayCreateMutable", referenced from:
_darwinssl_connect_step2 in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayGetCount", referenced from:
_darwinssl_connect_common in libcurl.a(libcurl_la-darwinssl.o)
"_CFArrayGetValueAtIndex", referenced from:
_darwinssl_connect_common in libcurl.a(libcurl_la-darwinssl.o)
"_CFDataCreate", referenced from:
_append_cert_to_array in libcurl.a(libcurl_la-darwinssl.o)
As I understand it wants to get links for darwinssl, but I do not know where to get those.
The readme for curl (https://github.com/biasedbit/curl-ios-build-scripts/blob/master/README.md) - does mention it depends on libz.dylib and
Security.framework but does not give any clues about what they are, when and how do I need them, and how to include those.
P.S. the regular curl inclusion works fine: g++ tornado.cc -o tornado -lcurl -std=c++11
I found some time to mess around on the mac. Here's the command that worked for me:
gcc main.cpp -I path/to/include path/to/libcurl.a -framework Foundation -lz -framework Security
Basically, you need -framework Foundation, -lz and -framework Security.

boost::filesystem Undefined symbols for architecture x86_64

I am very new with using GNU. I am trying to start using the boost filesystem library, and I keep getting these errors. I am trying to get the current working directory, by using boost::filesystem.
My code:
boost::filesystem::path full_path( boost::filesystem::detail::current_path() );
cout << "Current path is : " << full_path << endl;
My command:
g++ -I boost_1_58_0 main.cpp -o example
Result:
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::current_path(boost::system::error_code*)", referenced from:
_main in main-1c56eb.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main-1c56eb.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main-1c56eb.o
___cxx_global_var_init1 in main-1c56eb.o
ld: symbol(s) not found for architecture x86_64
Can someone please explain what the error is asking for? What did I do wrong?
boost.filesystem is not a header-only library. You have to link to the library using -L and -l flags. (And make sure the library is already properly built). You need to link to both boost_system and boost_filesystem libraries.
The command line could look like:
g++ -Iboost_1_58_0 -Lboost_1_58_0/lib/ -lboost-filesystem -lboost_system main.cpp -o example
(replace the -L argument with the path where the libboost-filesystem.so file resides)
Then, before you are able run the executable, you have to let the loader know where to look for the libraries. You shell be able do that using the following command:
export DYLD_LIBRARY_PATH=/path/to/boost/bib:$DYLD_LIBRARY_PATH
To make it automatic, I would recommend using a build system like cmake instead of just a command line.

cv::VideoCapture from string gives linker error in Qt5 on Mac

Problem
I am trying to get the OpenCV VideoCapture class running in a Qt project.
When I call it with an int (0 for the video camera on my mac), it works fine:
#include "opencv2/opencv.hpp"
#include <opencv2/highgui/highgui.hpp>
...
cv::VideoCapture cap(0);
The project compiles and when I run it, the light on my camera goes on.
BUT: when I try to compile it with a std::string as argument, I get a linker error:
#include "opencv2/opencv.hpp"
#include <opencv2/highgui/highgui.hpp>
...
cv::VideoCapture cap("/Users/xxxxx/small.mp4");
results in:
Undefined symbols for architecture x86_64:
"cv::VideoCapture::VideoCapture(std::string const&)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
althought the constructor from std::string should actually exist:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-videocapture
Settings
My specifications:
Qt 5.4.0 (Clang 6.0 (Apple), 64 bit)
Mac OSX 10.10.1
OpenCV 2.4.9 installed from homebrew
My .pro file:
QT += core gui widgets
TARGET = VideoCaptureTest
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_videostab
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
What I tried
1.
I found this question on SO, which seems to be the exact same problem as mine:
Linking error: undefined reference to `cv::VideoCapture::open(std::string const&)`
It seem my problem could have something to do with clashing versions of OpenCV. But I checked my include directories and my lib directories and I seem to only have 2.4.9 installed. Is there maybe a different version that comes with Qt?
I tried including version 2.4.9 directly in my .pro file with
LIBS += -lopencv_core2.4.9
...
But how can I make sure I include this version as well in my source file?
2.
I though it might have something to do with Mac and x86_64 stuff. I included the following lines, which I found somewhere online, in my .pro file:
CONFIG += x86 ppc x86_64 ppc64
CONFIG += MAC_CONFIG
MAC_CONFIG {
QMAKE_CXXFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7
QMAKE_LFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7
}
But this also showed no effect.
3.
Here (http://answers.opencv.org/question/14772/solved-linking-error-undefined-reference-to-cvvideocaptureopenstdstring-const/) it is suggested to try cv::String instead of std::string. I also tried this:
#include "opencv2/opencv.hpp"
...
cv::String s("/Users/xxxxx/small.mp4");
cv::VideoCapture cap(s);
and strangely I still get the exact same error:
Undefined symbols for architecture x86_64:
"cv::VideoCapture::VideoCapture(std::string const&)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
which seems like the cv::String is actually converted to std::string, I guess because the compiler somewhere finds the definition of the constructor with std::string, but the linker does not?
4.
Apparently there was a similar problem with OSX 10.9, not with cv::VideoCapture, but in general resulting also in linking error for x86_64. The solution was to include
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
in the .pro file. I tried this as well with 10.9 and 10.10 (which I am actually using). Still the same error. Could this be a problem with my version of OSX?
Help
I found no other suggestions on how to solve the problem. Does somebody have an idea what I am doing wrong? Any help appreciated!
Patrick
The answer has been given in the discussion(#wezside) of the link (item 1 of your description).
for OpenCV 3.0 (also 2.4.9 ?)
you need to add
LIBS += -lopencv_videoio
to the .pro, which is missing in yours.
After researching for several hours, I found that adding QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11 to your .pro file and removing the previous .pro.user file and build directory can solve the problem. The second step is required.
I'm on El Capitan.

Boost Tcp-Asio-Server Link failure using Qt on Mac

I have a very simple class, which I will send as Object via TCP using Asio by boost. I found many examples on the Internet, but when I compile my code I get a Link Failure.
#include <boost/archive/text_oarchive.hpp>
void async_write(){
std::ostringstream archive_stream;
boost::archive::text_oarchive archive(archive_stream); // here it fails
//....
}
I downloaded boost via macports.
My Qt project file:
INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib
LIBS += -lboost_system-mt -lboost_filesystem-mt -lboost_serialization-mt
Failure:
Undefined symbols for architecture x86_64:
"boost::archive::text_oarchive_impl::save(std::string const&)", referenced from:
void boost::archive::save_access::save_primitive(boost::archive::text_oarchive&, std::string const&) in tcpsession.o
"boost::archive::text_oarchive_impl::text_oarchive_impl(std::ostream&, unsigned int)", referenced from:
boost::archive::text_oarchive::text_oarchive(std::ostream&, unsigned int) in tcpsession.o
"boost::archive::basic_text_oprimitive::~basic_text_oprimitive()", referenced from:
boost::archive::text_oarchive_impl::~text_oarchive_impl() in tcpsession.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: * [tcpserver] Error 1
Any help is appreciated.
The standard reply would be "re-run qmake". It's even simpler to just delete the entire shadow build directory. One level up from the source of your project, there will be build-... folders. Delete all of them, and build again.
The simplest way to see whether your project file (the file with LIBS += lines) is current, add something to it that's invalid (like a typo in the library name). If it still "builds" without showing the error directly aimed at your typo (a missing library), then you know that your build is not based on the current project file, and you should re-run qmake or delete the shadow build folder so that everything will be recreated there.