Ask Your Question
1

Undefined symbols for architecture x86_64 for c++, python works fine

asked 2019-06-13 15:40:27 -0500

machineelf gravatar image

updated 2019-06-13 23:33:04 -0500

berak gravatar image

I am trying to compile a very simple code with g++ (MacPorts gcc8 8.3.0_0) 8.3.0. I installed opencv4.1.0_2 with homebrew and it works perfectly for python. I need to switch to c++ at this point to use more transparent api functions. My code is:

#include <thread>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;
const string ip = "192.168.122.1";

const string url1 = "http://"+ip+":8081/?action=stream";
const string url2 = "http://"+ip+":8082/?action=stream";
const string url3 = "http://"+ip+":8083/?action=stream";
const string url4 = "http://"+ip+":8084/?action=stream";
const string url5 = "http://"+ip+":8080/?action=stream";
const string url6 = "http://"+ip+":8085/?action=stream";
const string url7 = "http://"+ip+":8086/?action=stream";

void VideoGet(string url) {
    UMat frame;
    VideoCapture cap(url);
    cap.open(url);
    if (!cap.isOpened()) {
        cerr << "Unable to open camera "+url+"\n";
        return;
    }
    while (true) {
        cap.read(frame);
        if (frame.empty()) {
            cerr << "Grabbed blank frame\n";
            break;
        }
    }
}
int main() {
    thread cam1(VideoGet,url1);
    thread cam2(VideoGet,url2);
    thread cam3(VideoGet,url3);
    thread cam4(VideoGet,url4);
    thread cam5(VideoGet,url5);
    thread cam6(VideoGet,url6);
    thread cam7(VideoGet,url7);
}

I compile with g++ ttc_multi_osx.cpp 'pkg-config opencv4 --cflags --libs' -o ttc_multi_osx.o and the compiler throws

Undefined symbols for architecture x86_64:
"cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
VideoGet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) in ccgUe88M.o
"cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
VideoGet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) in ccgUe88M.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Any help would be very much appreciated.

edit retag flag offensive close merge delete

Comments

LBerger gravatar imageLBerger ( 2019-06-14 03:12:40 -0500 )edit

I tried all the suggestions in there. I ran brew unlink opencv && brew link opencv but I still get the same ld errors.

machineelf gravatar imagemachineelf ( 2019-06-16 23:44:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-06-20 16:03:09 -0500

machineelf gravatar image

The problem was that I was compiling with macports g++, not Xcode g++, which must have been how homebrew compiled opencv during the install. I solved this by adding the Xcode g++ path to my $PATH variable, which I found by running xcodebuild -find g++, and unlinking macports g++ by running sudo port select --set gcc none.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-06-13 15:40:27 -0500

Seen: 52 times

Last updated: Jun 20