Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:46:57+00:00 2026-05-25T18:46:57+00:00

I have installed OpenCV. I have been able to compile some code but sometimes

  • 0

I have installed OpenCV.
I have been able to compile some code but sometimes it does not work. The example below does not work.

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"

int main (int argc, char* argv[])
{
    try
    {
        cv::Mat src_host = cv::imread("building.jpg", CV_LOAD_IMAGE_GRAYSCALE);
        cv::gpu::GpuMat dst, src;
        src.upload(src_host);

        cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);

        cv::Mat result_host = dst;
        cv::imshow("Result", result_host);
        cv::waitKey();
    }
    catch(const cv::Exception& ex)
    {
        std::cout << "Error: " << ex.what() << std::endl;
    }
    return 0;
}

I get the following errors when I compile with

gcc Test.cpp $(pkg-config –cflags –libs opencv)

gcc Test.cpp $(pkg-config --cflags --libs opencv)
Undefined symbols for architecture x86_64:
"std::allocator<char>::allocator()", referenced from:
  _main in ccnzUIww.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
  _main in ccnzUIww.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
  _main in ccnzUIww.o
"std::terminate()", referenced from:
  _main in ccnzUIww.o
"std::allocator<char>::~allocator()", referenced from:
  _main in ccnzUIww.o
"cv::gpu::GpuMat::upload(cv::Mat const&)", referenced from:
  _main in ccnzUIww.o
"cv::gpu::Stream::Null()", referenced from:
  _main in ccnzUIww.o
"cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)", referenced from:
  _main in ccnzUIww.o
"cv::gpu::GpuMat::operator cv::Mat() const", referenced from:
  _main in ccnzUIww.o
"___cxa_begin_catch", referenced from:
  _main in ccnzUIww.o
"std::cout", referenced from:
  _main in ccnzUIww.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
  _main in ccnzUIww.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
  _main in ccnzUIww.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
  _main in ccnzUIww.o
"___cxa_end_catch", referenced from:
  _main in ccnzUIww.o
"std::ios_base::Init::Init()", referenced from:
  __static_initialization_and_destruction_0(int, int)in ccnzUIww.o
"std::ios_base::Init::~Init()", referenced from:
  ___tcf_0 in ccnzUIww.o
"cv::gpu::GpuMat::release()", referenced from:
  cv::gpu::GpuMat::~GpuMat()in ccnzUIww.o
"___gxx_personality_v0", referenced from:
  Dwarf Exception Unwind Info (__eh_frame) in ccnzUIww.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I have also tried:

  • gcc Test.cpp $(pkg-config –cflags –libs opencv) -m32
  • gcc Test.cpp $(pkg-config –cflags –libs opencv) -m64
  • nvcc Test.cpp $(pkg-config –cflags –libs opencv)

But this also give errors. I have looked for answers on stackoverflow and found this. Compiling OpenCV CUDA program
In this answer the solution is to use this command:

g++ Test.cpp `pkg-config --cflags --libs opencv` -lopencv_gpu

And it works! I have tried giving the same argument to the gcc and nvcc compiler but then I get errors again. This is a problem since I have to use the nvcc compiler because I want to use OpenCV in a CUDA project.

I have little experience with C and C++ so there is a possibility that it is something obvious 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:46:57+00:00Added an answer on May 25, 2026 at 6:46 pm

    For compiling and linking C code you should use gcc

    For compiling and linking C++ code you should use g++

    Although gcc can often correctly guess what language to compile a file as, it can usually not link to the needed libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed NppExecute plugin in notepad++. I am not able to figure out
I am not a Unix guy, so I have been trying to install openCV
I need to install OpenCV on Win32. I do not have it installed currently.
I have been trying to set up OpenCV for the past few days with
I have installed VS2008 and am able to run the demo codes camshiftdemo and
I have opencv installed and working on my iphone (big thanks to this community).
I have installed usb driver, selected the android device's debugging mode but i can't
I have installed Eclipse+CDT and OpenCV with: $ sudo apt-get install libcv1 libcv-dev libcvaux1
I have tried to install ruby-opencv and I can't get it to work. I
I'm having some issues. I've installed OpenCV 2.3 on an ec2 ubuntu instance -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.