Opencv program using qtcreator undefined reference in ubuntu for imread or any string - qt-creator

include "mainwindow.h"
include "ui_mainwindow.h"
include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat inputImage = cv::imread("/home/chaiein/VR/1.jpg");
cv::imshow("Display Image", inputImage);
}
MainWindow::~MainWindow()
{
delete ui;
}
Error
/home/chaiein/VR/linePose/mainwindow.cpp:11: error: undefined reference to `cv::imread(std::__cxx11::basic_string, std::allocator > const&, int)'
My linepose.pro file as the following content
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = linePose
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv /opt/ros/kinetic/share/OpenCV-
3.2.0-dev
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I have searched in many links but this problem seems to have different solution please help me!!

Related

PCL viewer inside QtCreator widget with VTK and QVTKOpenGLStereoWidget

I need to make a graphical window with a Qt widget that allows to represent inside it a point cloud that I have previously loaded using the PLC library.
Here's what I have so far that doesn't work (I based it on tutorials and this answer).
I'm using:
Ubuntu 20.04
Qt Creator 5.15
VTK 9.1
PCL 1.12
The reason I am using QVTKOpenGLStereoWidget is that as far as I read both QVTKOpenGLWidget and QVTKWidget are no longer available or will be discontinued in future releases.
Test.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++14
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
MainWindow.cpp
HEADERS += \
MainWindow.h
FORMS += \
MainWindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
# INCLUIR LAS LIREARÍAS PARA EL PRROGRAMA
VTK_VERSION = 9.1
PCL_VERSION = 1.12
CONFIG += link_pkgconfig
# LIBREARÍA DE ARCHIVOS DE EIGEN3
PKGCONFIG += eigen3
# LIBRERÍA DE ARCHIIVOS DE BOOST
INCLUDEPATH += /usr/include/boost
# LIBREARÍA DE REPRESENTACIÓN GRÁFICA VTK
INCLUDEPATH += /usr/local/include/vtk-$${VTK_VERSION}
LIBS += -L/usr/local/lib \
-lvtkCommonColor-$${VTK_VERSION} \
-lvtkCommonCore-$${VTK_VERSION} \
-lvtkFiltersSources-$${VTK_VERSION} \
-lvtkInteractionStyle-$${VTK_VERSION} \
-lvtkRenderingContextOpenGL2-$${VTK_VERSION} \
-lvtkRenderingCore-$${VTK_VERSION} \
-lvtkRenderingFreeType-$${VTK_VERSION} \
-lvtkRenderingGL2PSOpenGL2-$${VTK_VERSION} \
-lvtkRenderingOpenGL2-$${VTK_VERSION} \
-lvtkCommonExecutionModel-$${VTK_VERSION} \
-lvtkRenderingFreeType-$${VTK_VERSION} \
-lvtkInteractionStyle-$${VTK_VERSION} \
-lvtkRenderingOpenGL2-$${VTK_VERSION} \
-lvtkRenderingLOD-$${VTK_VERSION} \
-lvtkCommonDataModel-$${VTK_VERSION} \
-lvtkCommonMath-$${VTK_VERSION} \
-lvtkViewsQt-$${VTK_VERSION} \
#-lvtkGUISupportQtOpenGL-$${VTK_VERSION} \
-lvtkGUISupportQt-$${VTK_VERSION}
# LIBRERÍAS PARA EL TRBAJO CON NUBES DE PUNTOS.
INCLUDEPATH += /usr/local/include/pcl-$${PCL_VERSION}
LIBS += -L/usr/local/lib \
-lpcl_common -lpcl_features -lpcl_filters -lpcl_io_ply \
-lpcl_io -lpcl_kdtree -lpcl_keypoints -lpcl_ml \
-lpcl_octree -lpcl_outofcore -lpcl_people -lpcl_recognition \
-lpcl_registration -lpcl_search -lpcl_segmentation -lpcl_stereo \
-lpcl_surface -lpcl_tracking -lpcl_visualization -lpcl_sample_consensus
MainWindow.ui
It only has one widget that has a promote a QVTKOpenGLSTereoWidget
MainWindow.h
I did the initialization of the VTK library, the inclusion of the different library headers and created the PCL viewer and the VTK renderer based on OpenGL.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "pcl/visualization/cloud_viewer.h"
#include <pcl/visualization/pcl_visualizer.h>
#include "pcl/io/pcd_io.h"
#include "pcl/io/ply_io.h"
#include "pcl/io/obj_io.h"
#include "pcl/common/io.h"
#include "vtkCylinder.h"
#include "vtkCylinderSource.h"
#include "vtkRenderWindow.h"
#include <QVTKOpenGLWidget.h>
#include <QVTKOpenGLStereoWidget.h>
#include <QVTKOpenGLWindow.h>
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
using namespace pcl::visualization;
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
pcl::visualization::PCLVisualizer::Ptr viewer;
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow;
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
MainWindow.cpp
Finally in the constructor of the MainWindow class I simply loaded the file (in this case it was a PLY) and then I tried to make the graphical representation in the widget
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
// Cargar el objeto en dicha nube de putnos en el formato que se desee.
pcl::io::loadPLYFile("/home/alejandro/Documentos/alejandro.ply",*cloud);
viewer->addPointCloud(cloud);
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
//renderWindow->AddRenderer(renderer); THIS MAKES AN ERROR!!
viewer.reset(new PCLVisualizer(renderer, renderWindow, "viewer", false));
ui->widget->setRenderWindow(viewer->getRenderWindow());
ui->widget->update();
}
MainWindow::~MainWindow()
{
delete ui;
}
Main.cpp
I have not changed anything, it is default
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
ERROR.
The main error I have is: /usr/local/include/vtk-9.1/vtkSmartPointer.h:225: error: incomplete type ‘vtkGenericOpenGLRenderWindow’ used in nested name specifier
In file included from /usr/local/include/pcl-1.12/pcl/visualization/point_cloud_geometry_handlers.h:49,
from /usr/local/include/pcl-1.12/pcl/visualization/common/actor_map.h:40,
from /usr/local/include/pcl-1.12/pcl/visualization/pcl_visualizer.h:48,
from /usr/local/include/pcl-1.12/pcl/visualization/cloud_viewer.h:39,
from ../04_pcl_viewer_V3/MainWindow.h:6,
from ../04_pcl_viewer_V3/MainWindow.cpp:1:
/usr/local/include/vtk-9.1/vtkSmartPointer.h: In instantiation of ‘static vtkSmartPointer vtkSmartPointer::New() [with T = vtkGenericOpenGLRenderWindow]’:
../04_pcl_viewer_V3/MainWindow.cpp:16:67: required from here
/usr/local/include/vtk-9.1/vtkSmartPointer.h:225:69: error: incomplete type ‘vtkGenericOpenGLRenderWindow’ used in nested name specifier
225 | static vtkSmartPointer New() { return vtkSmartPointer(T::New(), NoReference()); }
| ~~~~~~^~
I was finally able to find the solution to the problem so I am sharing it as an answer in case it could be useful for someone else.
pclTest_V0.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++14
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
MainWindow.cpp
HEADERS += \
MainWindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
# Incluir la librería y la ruta de VTK
VTK_VERSION = 9.1
INCLUDEPATH += /usr/local/include/vtk-$${VTK_VERSION}
LIBS += -L/usr/local/lib \
-lvtkCommonColor-$${VTK_VERSION} \
-lvtkCommonExecutionModel-$${VTK_VERSION} \
-lvtkCommonCore-$${VTK_VERSION} \
-lvtkCommonDataModel-$${VTK_VERSION} \ # Para PCL
-lvtkCommonMath-$${VTK_VERSION} \ # Para PCL
-lvtkFiltersCore-$${VTK_VERSION} \
-lvtkFiltersSources-$${VTK_VERSION} \
-lvtkInfovisCore-$${VTK_VERSION} \
-lvtkInteractionStyle-$${VTK_VERSION} \
-lvtkRenderingContextOpenGL2-$${VTK_VERSION} \
-lvtkRenderingCore-$${VTK_VERSION} \
-lvtkRenderingFreeType-$${VTK_VERSION} \
-lvtkRenderingGL2PSOpenGL2-$${VTK_VERSION} \
-lvtkRenderingOpenGL2-$${VTK_VERSION} \
-lvtkViewsQt-$${VTK_VERSION} \
-lvtkGUISupportQt-$${VTK_VERSION} \
-lvtkRenderingQt-$${VTK_VERSION}
# Incluir el directorio de boost.
INCLUDEPATH += /usr/include/boost
# Incluir el direcotrio de eigen3.
INCLUDEPATH += /usr/include/eigen3
# Incluir las librerías y la ruta de PCL.
PCL_VERSION = 1.12
INCLUDEPATH += /usr/local/include/pcl-$${PCL_VERSION}
LIBS += -L/usr/local/lib \
-lpcl_common -lpcl_io -lpcl_visualization
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "pcl/common/common_headers.h"
#include "pcl/features/normal_3d.h"
#include "pcl/io/obj_io.h"
#include "pcl/io/ply_io.h"
#include "pcl/visualization/pcl_visualizer.h"
#include "pcl/console/parse.h"
#include "QVTKOpenGLNativeWidget.h"
#include "vtkCamera.h"
#include "vtkCubeSource.h"
#include "vtkDataObjectToTable.h"
#include "vtkElevationFilter.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkNamedColors.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkQtTableView.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkVersion.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
pcl::visualization::PCLVisualizer::Ptr viewer;
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "MainWindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
vtkNew<vtkRenderer> renderer;
renderWindow->AddRenderer(renderer);
// Crear una nube de puntos con los datos almacenados en un archivo
// determinado.
std::string name = "filename.ply";
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPLYFile(name,*cloud);
// Generar el visor de la nube de puntos para realizar la visualización.
//viewer.reset(new pcl::visualization::PCLVisualizer("viewer",false));
viewer.reset(new pcl::visualization::PCLVisualizer(renderer, renderWindow,
"viewer",false));
viewer->addPointCloud(cloud);
//ui->Viewer_widget->renderWindow()->AddRenderer(renderer);
ui->Viewer_widget->setRenderWindow(viewer->getRenderWindow());
ui->Viewer_widget->update();
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow.ui
Widget with QVTKOpenGLNativeWidget.h promotion.

Can't GTK3 programs be in multiple source files?

I am trying to make a C-program with multiple c-files in GTK3.
As models I am using:
how-to-split-a-c-program-into-multiple-files
and this
example-0.c
My program looks like this:
Functions.c (with the function activate)
#include "Functions.h"
#include <gtk/gtk.h>
#include "stdio.h"
static void activate (GtkApplication* app, gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_widget_show_all (window);
}
Function.h (the header file)
#include <gtk/gtk.h>
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
static void activate (GtkApplication* app, gpointer user_data);
#endif
Main.c
#include "stdio.h"
#include <gtk/gtk.h>
#include "Functions.h"
int main(int argc, char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
When I compile, is says:
gcc -Wall `pkg-config --cflags gtk+-3.0` Functions.c Main.c `pkg-config --libs gtk+-3.0`
Functions.c:7:13: warning: ‘activate’ defined but not used [-Wunused-function]
static void activate (GtkApplication* app, gpointer user_data)
^
In file included from Main.c:4:0:
Functions.h:7:14: warning: ‘activate’ used but never defined
static void activate (GtkApplication* app, gpointer user_data);
^
/tmp/ccWzazr0.o: I funktionen "main":
Main.c:(.text+0x38): undefined reference to `activate'
collect2: error: ld returned 1 exit status
and is not compiled!
Yes, GTK programs can be split into multiple C files.
You get an error because you are telling your compiler that the function is only visible within that single C source file:
static void activate (GtkApplication* app, gpointer user_data)
If you want to use that function from another source file, you need to remove static keyword.
Both in the header file as well in the C file you need to remove it.

Link error with Qt5 webkit

I want to make a browser in qt5 using qtwebkit but I found some error when I get download my site. I don't know the reason. I added the webkit library, and call it in mainwindow.h:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWebKit/QtWebKit>
namespace Ui { class MainWindow; }
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
private:
Ui::MainWindow *ui; };
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->webView->back();
}
void MainWindow::on_pushButton_2_clicked()
{
ui->webView->forward();
}
void MainWindow::on_pushButton_3_clicked()
{
ui->webView->reload();
}
void MainWindow::on_pushButton_4_clicked()
{
ui->webView->load("http://" + ui->lineEdit->text());
}
and this when i called library
#-------------------------------------------------
#
# Project created by QtCreator 2013-10-31T07:39:06
#
#-------------------------------------------------
QT += core gui QT += webkit
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mozilabrwser TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I tried to change the name of webkit but I still get this error:
D:\ubunto\QT5\Tools\QtCreator\bin\mozilabrwser\mainwindow.cpp:19: error:
undefined reference to `_imp___ZN8QWebView4backEv'
QT += core gui QT += webkit
is wrong. You seem to be using Qt 5, and in Qt 5 the correct module is webkitwidgets. 2nd issue is format, you seem to have two lines concatenated. So this should work:
QT += core gui
QT += webkitwidgets
Note: If you need to have the program compile with both Qt4 and Qt5, then you need to use conditional, adding webkit for Qt4, webkitwidgets for Qt5. But this is probably not a concern for a hobby project, no point clutteirng the .pro file with that stuff until you actually need it (you will also need some source changes and #ifdef stuff in code if you want to support both, so don't go there unless it is an important requirement).
Same two lines concatenated issue seems to be also in line TARGET = mozilabrwser TEMPLATE = app.

Linker error with Boost Serialization using a particular class in a test executable, but not in production executable

I'm using Boost 1.49, OpenCV 2.3.1, CMake 2.8 in a C++ project.
I'm building two executables with the same header file, one for production and the other for testing. The contest.hpp file specifies:
namespace boost
{
namespace serialization
{
template<class Archive>
void serialize(Archive& ar, cv::Point& p, const unsigned int version);
template<class Archive>
void serialize(Archive& ar, cv::Rect_<int>& r, const unsigned int version);
template<class Archive>
void serialize(Archive& ar, cv::Size_<int>& s, const unsigned int version);
}
}
and these are implemented in contest.cpp file like
namespace boost
{
namespace serialization
{
template<class Archive>
void serialize(Archive& ar, cv::Point& p, const unsigned int version)
{
ar & p.x;
ar & p.y;
}
template<class Archive>
void serialize(Archive& ar, cv::Rect_<int>& r, const unsigned int version)
{
ar & r.x;
ar & r.y;
ar & r.height;
ar & r.width;
}
template<class Archive>
void serialize(Archive& ar, cv::Size_<int>& s, const unsigned int version)
{
ar & s.width;
ar & s.height;
}
}
}
And test-contest.cpp mundanely tests these like
BOOST_AUTO_TEST_CASE(Serialization1)
{
Point point_write(3, 5);
{
ofstream point_file("Point.txt");
ar::text_oarchive point_archive(point_file);
sr::serialize(point_archive, point_write, 0);
}
Point point_read(0, 0);
{
ifstream point_file("Point.txt");
ar::text_iarchive point_archive(point_file);
sr::serialize(point_archive, point_read, 0);
}
BOOST_CHECK(point_read == point_write);
Rect rect_write(3, 5, 1, 7);
{
ofstream rect_file("Rect.txt");
ar::text_oarchive rect_archive(rect_file);
sr::serialize(rect_archive, rect_write, 0);
}
Rect rect_read(0, 0, 0, 0);
{
ifstream rect_file("Rect.txt");
ar::text_iarchive rect_archive(rect_file);
sr::serialize(rect_archive, rect_read, 0);
}
BOOST_CHECK((rect_read.x) == (rect_write.y) && (rect_read.y) == (rect_write.y));
Size size_write(3, 5);
{
ofstream size_file("Size.txt");
ar::text_oarchive size_archive(size_file);
sr::serialize(size_archive, size_write, 0);
}
Size size_read(0, 0);
{
ifstream size_file("Size.txt");
ar::text_iarchive size_archive(size_file);
sr::serialize(size_archive, size_read, 0);
}
BOOST_CHECK(size_read == size_write);
}
where sr and ar are defined in common.hpp like
namespace ar = ::boost::archive;
namespace sr = ::boost::serialization;
The makefiles are produced from CMake configuration like:
link_directories(${DEPENDENCY_DIR}/libboost/lib)
link_directories(${DEPENDENCY_DIR}/libopencv/lib)
add_executable(test-contest test-contest.cpp contest.cpp)
add_executable(contest main.cpp contest.cpp)
target_link_libraries(test-contest boost_serialization opencv_core opencv_highgui opencv_imgproc boost_program_options boost_unit_test_framework boost_filesystem)
target_link_libraries(contest boost_serialization opencv_core opencv_highgui opencv_imgproc boost_program_options boost_filesystem)
so, the moral of the story is, both contest and test-contest are compiled and linked against the same header and libraries. Note that other Boost libraries are linked and tested successfully.
When it comes to make after cmake 'Unix Makefiles' .., for contest it says
[ 40%] Building CXX object CMakeFiles/contest.dir/main.cpp.o
[ 60%] Building CXX object CMakeFiles/contest.dir/contest.cpp.o
Linking CXX executable contest
[ 60%] Built target contest
but for test-contest
[ 80%] Building CXX object CMakeFiles/test-contest.dir/test-contest.cpp.o
[100%] Building CXX object CMakeFiles/test-contest.dir/contest.cpp.o
Linking CXX executable test-contest
CMakeFiles/test-contest.dir/test-contest.cpp.o: In function `otap::TPageImage::Serialization1::test_method()':
/home/iesahin/Repository/otapexplorer/cli/contest-2012/test-contest.cpp:119: undefined reference to `void boost::serialization::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, cv::Rect_<int>&, unsigned int)'
/home/iesahin/Repository/otapexplorer/cli/contest-2012/test-contest.cpp:125: undefined reference to `void boost::serialization::serialize<boost::archive::text_iarchive>(boost::archive::text_iarchive&, cv::Rect_<int>&, unsigned int)'
/home/iesahin/Repository/otapexplorer/cli/contest-2012/test-contest.cpp:133: undefined reference to `void boost::serialization::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, cv::Size_<int>&, unsigned int)'
/home/iesahin/Repository/otapexplorer/cli/contest-2012/test-contest.cpp:139: undefined reference to `void boost::serialization::serialize<boost::archive::text_iarchive>(boost::archive::text_iarchive&, cv::Size_<int>&, unsigned int)'
collect2: ld returned 1 exit status
make[2]: *** [test-contest] Error 1
And IMHO the weirdest part is, there are no errors for serialize(Archive, cv::Point, int) which is from the same header/library in OpenCV with serialize(Archive, cv::Rect_<int>, int) or cv::Size_<int>. Their serialization/test functions are almost identically defined.
I'm linking these serialize functions from contest.cpp file successfully. I tried replacing Rect with Rect_<int> in the definitions, to no change. I tried changing the order of libraries in CMakeLists.txt and took boost_serialization from the end to its current place, to no avail.
Where am I doing it wrong?
I think you need the implementations of your three serialize functions moved from contest.cpp to contest.hpp.
For the reasons why, see Why can templates only be implemented in the header file? or Why should the implementation and the declaration of a template class be in the same header file?

What is the exact equivalent to LD_PRELOAD on OSX?

I am using LD_PRELOAD to hook a library function, and in Linux it works perfectly. But I cannot figure out how to do the equivalent in OSX.
The setup I have on Linux is as follows:
The code is:
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <unistd.h>
#include <ruby.h>
void
rb_raise(unsigned long exc, const char *fmt, ...)
{
static void (*libruby_rb_raise)
(unsigned long exc, const char *fmt, ...) = NULL;
void * handle;
char * error;
if (!libruby_rb_raise) {
handle = dlopen("/path/to/libruby.so",
RTLD_LAZY);
if (!handle) {
fputs(dlerror(), stderr);
exit(1);
}
libruby_rb_raise = dlsym(handle, "rb_raise");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
}
}
// ...code...
return Qnil;
}
Which I then compile with:
gcc -Wall -O2 -fpic -shared -ldl -g -I/path/to/includes/ -o raise_shim.so raise_shim.c
I then execute with:
LD_PRELOAD=./raise_shim.so ruby
All of the above works well on Linux, what is the equivalent for each step to get this working on OSX? I have googled this and have not been able to get it to work with the information provided as the info for some of the steps are missing.
Thanks in advance!
Take a look at DYLD_INSERT_LIBRARIES. That's the variable you're looking for.
See also this answer.

Resources