Что делать с ошибкой undefined reference to при передаче параметра в функцию?
Имеется Qt_5_3_MinGW_32bit, Windiws 7 64bit.
Работаю в графическом приложении QT.
В хэдере (mainwindow.h) обявлено следующее:
private:
QString image_path;
void separateImage(char* path_to_image);
Далее при нажатии на кнопку вызываю метод void separateImage(char* path_to_image);
mainwindow.cpp :
На кнопке написано следующее:
QByteArray ba = image_path.toUtf8(); //image_path - путь до картинки
char *str;
str = ba.data();
separateImage(str); //тут компилятор говорит на ошибку
Возникающие ошибки:
D:QtProjectsLabArcheo_PartCeramicResiduesAsMosaicmainwindow.cpp:104: ошибка: undefined reference to `MainWindow::separateImage(char*)’
и
collect2.exe:-1: ошибка: error: ld returned 1 exit status
Данная ошибка возникает, если вместо char передавать QString, соответственно, изменив функцию separate_image.
Часть кода separate_image выглядит следующим образом:
void separateImage(char* path_to_image)
{
Mat src;
Mat src_gray;
int thresh = 100;
int max_thresh = 255;
string path;
path.assign(path_to_image, strlen(path_to_image));
//string bufstr = path_to_image->toStdString();
// qDebug("dddd %d",bufstr);
src = cv::imread(path, 1);
cvtColor(src, src_gray, CV_BGR2GRAY);
}
Compiler error in mingw-w64: ‘undefined reference to `__getreent.’
I’m currently in the (nightmare) task of trying to compile cImg and libjpeg in Windows. After many hours, I was finally able to build libjpeg and I’ve included it within the build process (cImg needs libjpeg to work with jpegs).
When I try to compile with ‘g image.cpp libjpeg.a -lgdi32’ I get the following error:
'jerror.c:112: undefined reference to `__getreent. The system cannot find the path specified.'
I’ve had a look on google but there doesn’t seem to be many people with the same issue (and fewer still with answers).
I’m compiling in windows using mingw-w64.
Undefined reference to template function
The implementation of a non-specialized template must be visible to a translation unit that uses it.
The compiler must be able to see the implementation in order to generate code for all specializations in your code.
This can be achieved in two ways:
1) Move the implementation inside the header.
2) If you want to keep it separate, move it into a different header which you include in your original header:
util.h
namespace Util
{
template<class T>
QString convert2QString(T type , int digits=0);
}
#include "util_impl.h"
util_impl.h
namespace Util
{
template<class T>
QString convert2QString(T type, int digits=0)
{
using std::string;
string temp = (boost::format("%1") % type).str();
return QString::fromStdString(temp);
}
}
Undefined reference to?
Язык Си (как, впрочем, и большинство ассемблеров) собирает cpp-файлы воедино неязыковыми средствами: makefile’ами и файлами проектов. Сначала компилятор обрабатывает все единицы компиляции отдельно друг от друга, а потом линкер собирает из того, что получилось, исполняемый файл. Разумеется, если где-то какой-то функции не нашлось, это можно опознать только при линковке.
Вот полный код программы:
Код был написан разработчиками оборудования, они утверждают, что он должен без проблем работать. В итоге были ошибки, я их исправил, но это не знаю как решить.