can't call any functions with devIL - c++

I would like to be able to use the devIL library for a project I am working on, but for some reason I cannot get it set up correctly. In my project, I have:
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
If I do not call any devIL functions, then the file will compile with no errors. However, as soon as I include
ilInit();
I get
undefined reference to `ilInit'
collect2: ld returned 1 exit status
What am I doing wrong?
Edit: I am running Ubuntu 11.10

Apparently you are including the headers, but not linking the binaries. With gcc, this can be done using the -l-option.

Related

How do I link a C++ library with CGO and Swig?

I want to use the C++ program xmr-stak in my Go program. After some research, I settled on SWIG to generate the bindings. The issue is that ld cannot find the library file. I'll just write down step by step what I did.
I created this file at src/miner/xmrstak/xmrstak.swigcxx along with the source code of xmr-stak:
%module xmrstak
%{
#include "xmrstak/net/jpsock.hpp"
#include "xmrstak/jconf.hpp"
#include "xmrstak/misc/executor.hpp"
%}
%include "xmrstak/misc/executor.hpp"
Since Swig is supported by Go, it will automatically generate the bindings at build time. But Go still requires a package name, so I've just created package.go:
package xmrstak
Now, I can build this project, which results in lots of errors like:
/tmp/go-build176223381/gitlab.com/jgillich/autominer/miner/xmrstak/_obj/xmrstak_wrap.cxx.o: In function `executor::inst()':
./xmrstak/misc/executor.hpp:35: undefined reference to `executor::executor()'
To fix this, it appears I need to tell ld to link the library. I've added the following to my package.go:
// #cgo LDFLAGS: -L${SRCDIR}/xmrstak/ -l${SRCDIR}/libxmr-stak-backend.a
import "C"
And copied the libxmr-stak-backend.a in the same folder. This file is obtained by building xmr-stak using cmake . && make and should include everything I need (for now).
My issue is that this doesn't actually work. I get the following output:
$ go install
# gitlab.com/jgillich/autominer/miner/xmrstak
xmrstak/misc/executor.hpp:43: Warning 507: No Go typemap defined for ex_event &&
[further warnings ommitted]
# gitlab.com/jgillich/autominer/miner/xmrstak
/usr/bin/ld: cannot find -l/home/jgillich/go/src/gitlab.com/jgillich/autominer/miner/xmrstak/libxmr-stak-backend.a
collect2: error: ld returned 1 exit status
The file however definitely exists:
$ ls
libxmr-stak-backend.a package.go xmrstak xmrstak.swigcxx
$ file /home/jgillich/go/src/gitlab.com/jgillich/autominer/miner/xmrstak/libxmr-stak-backend.a
/home/jgillich/go/src/gitlab.com/jgillich/autominer/miner/xmrstak/libxmr-stak-backend.a: current ar archive
Did I do anything wrong here?
This fixed it for me:
// #cgo LDFLAGS: -L${SRCDIR} -lxmr-stak-backend
import "C"
Seems like I was just using ld wrong.

vtk autoinit linker error

I have a very confusing (at least for me :) ) problem with linking to vtk-libraries. On one desktop pc, my code compiles without any error. I have an identical installation on another pc, but there, I get linker errors.
On both pc's are installed: itk 4.8, vtk 6.3 and cmake 3.3. Both are debian-systems (8.1 - jessie).
[ 96%] Linking CXX executable project
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit::~vtkRenderingVolume_AutoInit()':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit::~vtkRenderingVolumeOpenGL_ModuleInit()':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Destruct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolumeOpenGL_ModuleInit':
project/main.cpp:4: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
CMakeFiles/project.dir/main.cpp.o: In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
libcommon.a(datareader.cpp.o): In function vtkRenderingVolume_AutoInit':
/usr/local/include/vtk-6.3/vtkRenderingVolumeModule.h:44: undefined reference tovtkRenderingVolumeOpenGL_AutoInit_Construct()'
collect2: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:326: recipe for target 'project' failed
I tried to fix those errors with adding
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
to the file where I am using the vtk libraries, but it didn't help.
Does anyone know what I'm doing wrong? I am wondering, why it works on one of those pcs but not on the other one.
thank you very much!
Update: I fixed my problem by switching the position of
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
in the CMakeLists to the end. However, does anyone know, why it makes such a huge difference for different pcs?
As long as the VTK_USE_FILE is found, your code should compile correctly. In your other PC, VTK_USE_FILE was already found from a previous configuration and sits in a CMake cache entry, so that is why it compiles fine.
If your are using Nightly,
Your should put these in front of your including any vtk headers.
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
and link all the library you made from vtk source

QtAddon SerialPort from Qt4 to Qt5

I am migrating a project from Qt4 to Qt5. I finished migrating the project itself and now I am working on the libraries. So far I haven't had many problems converting and linking them to the project, but this one is throwing undefined references.
The project uses QtSerialPort, and it compiled perfectly using the Qt4 version of it, and it was linked like this in the .pro file:
-l:"C:/Users/Sprint/Desktop/swe/marssies/libQtSerialPort.a" \
I have compiled the Serial Port library with/for Qt5 and linked it as follows:
-l:"C:/Users/Sprint/Desktop/swe/marssies/libQt5SerialPort.a" \
But I keep getting these errors:
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4ecc): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::availablePorts()'
Makefile.Release:922: recipe for target '..\Release\Swibz.exe' failed
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4f3e): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::portName() const'
./release\gpssettingswidget.o:gpssettingswidget.cpp:(.text+0x4f5d): undefined reference to `QtAddOn::SerialPort::SerialPortInfo::description() const'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: ./release\gpssettingswidget.o: bad reloc address 0xd in section `.text$_ZN25Ui_GPSSettingsWidgetClass13retranslateUiEP14SettingsWidget[__ZN25Ui_GPSSettingsWidgetClass13retranslateUiEP14SettingsWidget]'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [..\Release\Swibz.exe] Error 1
I know its a linker error because of the "ld returned 1 exit status"
I have tried linking the libQt5SerialPortd.a, libQt5SerialPort.dll and libQt5SerialPortd.dll but it throws the same errors
(By the way, if someone knows the difference between libNAMEd.a and libNAME.a please share your knowledge)
Maybe the QtAddOn is now in another library? Because otherwise it shouldnt recognize many other functions, not only the ones with QtAddOn.
Thankyou very much. I don't know what I would do without stackoverflow.
EDIT Alright, I found this which tells to change any SerialPortInfo declared variable to QSerialPortInfo, I have done that in my project and I am getting new errors, but now I am not sure which #include I should put:
#include <QtSerialPort>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QtSerialPort/QtSerialPort>
I have tried each one of these and all give me errors. Ill keep trying and see if anything comes clear
QtSerialPort is now a part of Qt. It officially became part of Qt with the 5.1.0 release. If you use the new version of Qt there is no need to get the source code separately and link to it.
To use the module with Qt 5 add this line to your qmake project file:
QT += serialport
You can then include the header files. To use these classes in your application, use the following include statement:
#include <QtSerialPort/QtSerialPort>
There is quite good documentation for the classes. You can view it from Qt Assistant.

Boost header parser.hpp does not compile

I was installing a project which uses boost. I had finished compiling. During make all install I faced the following error:
CMakeFiles/config_example.dir/__/config_impl.cc.o: In function `boost::program_options::basic_command_line_parser<char>::run()':
/usr/local/include/boost/program_options/detail/parsers.hpp:107: undefined reference to `boost::program_options::detail::cmdline::get_canonical_option_prefix()'
collect2: error: ld returned 1 exit status
It reads like there is something wrong with the boost header. But this is improbable. So perhaps I am using it in the wrong way or something else is off here. Can you please help me figure out the issue. I am using boost 1.53
You need to link libboost_program_options. Programoptions is one of the few boost libraries that is not header only

/usr/bin/ld: cannot find -lCImg

I am newbie in C++ and Eclipse simultaneously...
I want to use CImg library but when I just used a line for it I have the problem that it is described below :
My code is:
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg <unsigned char> img(640,400,1,3);
return 0;}
and the error that I get is :
/usr/bin/ld: cannot find -lCImg
collect2: ld returned 1 exit status
I have searched a lot yesterday and I have tried many things that I found.
I tried almost everything for X11 library and pathread.
I changed many times the flags in the settings of the project...
Thank you in advance.
PS: I know that there is a similar(almost the same question) here g++: No such file or directory? but in my case I can not change the makefile.
CImg is a template-based library that is compiled 'on the fly' with your program, so it is not pre-compiled and thus doesn't have a libCImg.so or libCImg.a files associated to it.
You just don't need an option '-lCImg' when you call g++. Eventually, if you are using the display capabilities of CImg (which is the default behavior), you need to add
-lX11 -lpthread
on your compilation line, but that is all (and if you don't use CImgDisplay at all, those dependencies can be even removed by putting
-Dcimg_display=0
when compiling with g++).