Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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.

click to hide/show revision 2
retagged

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

berak gravatar image

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

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.

click to hide/show revision 3
retagged

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

berak gravatar image

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

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.

click to hide/show revision 4
retagged

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

berak gravatar image

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

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.