Reputation: 31
I've been trying to configure Eclipse CDT (on Ubuntu Precise) to compile a program using wxWidgets. I'm receiving errors with Eclipse, but the program compiles fine with a makefile that I have been provided with. I've followed the instructions given in http://wiki.wxwidgets.org/Eclipse#Linux, but still, no success. (I.e., I believe I've set up the compiler and linker flags up correctly.)
My header file is as follows:
#ifndef READIMAGE_H_
#define READIMAGE_H_
class Image{
wxImage *loadedImage;
public:
Image(string filename);
void loadImage(string filename){};
};
#endif /* READIMAGE_H_ */
My source file is as follows:
#include <wx/wx.h>
#include <wx/image.h>
#include <iostream>
using namespace std;
#include "readImage.h"
Image::Image(string file){
loadImage(file);
}
int main(){
Image img("example.jpg");
}
The errors I receive are:
make: *** [Image_IO] Error 1
Type 'wxImage' could not be resolved
undefined reference to `wxRect2DInt::operator=(wxRect2DInt const&)'
undefined reference to `wxRect2DInt::operator=(wxRect2DInt const&)'
undefined reference to `wxThread::~wxThread()'
In case this helps, the makefile is as follows:
INCS =
LIBP =
ARCH_CFLAGS =
#The code below should be used rather than the
#specific 2.4 version one. With this one we ensure
#that we run the latest release of wxGTK rather
#than a specific one:
WX_LIBS = `wx-config --libs --gl-libs`
WX_FLAGS = `wx-config --cxxflags`
LIBS = $(WX_LIBS)
ARCH_CFLAGS =
EXES = readImage
CFLAGS = $(ARCH_CFLAGS) $(WX_FLAGS) -Wall -Wno-unused -Wno-reorder \
-O3 -fomit-frame-pointer -fforce-addr
# ------------------
all : clean $(EXES)
clean :
find -name "*.o" -exec rm {} \;
rm -f ${EXES} -R
# ------------------
readImage : readImage.o
g++ readImage.o -o readImage $(ARCH_CFLAGS) $(LIBS) $(CFLAGS)
readImage.o : readImage.cpp readImage.h
g++ -c readImage.cpp $(ARCH_CFLAGS) $(INCS) $(WX_FLAGS)
# ------------------
Any ideas?
Many thanks in advance.
EDIT
In the command line pattern for the C++ compiler and linker (Project>Properties>GCC C++ Compiler and >GCC C++ Linker, respectively), if I move ${FLAGS} to the end of the pattern then I only receive the one error:
Type 'wxImage' could not be resolved
NOTE I'm not receiving warnings with any of the includes, suggesting that the compiler and linker can find the libraries.
Upvotes: 2
Views: 3603
Reputation: 167
Configure eclipse to work with wxWidgets a bit complicated. In my experience, there were some compiler flags and linker option need to be set accordingly, this may lead to confuse for beginer.
During my experience to work with eclipse, I found some easy way to make eclipse play well with wxWidgets, pls check this simplified installer that will help you to configure eclipse.
The installer initially targetted for raspberry pi board because it contain cross compiler toolchain built with buildroot. But target build for Linux x86_64 is also provided, as already tested on Ubuntu 14.04-LTS.
Please make a try and inform your mileage.
http://yasriady.blogspot.co.id/2016/01/raspberry-pi-toolchain.html
Rgrds/Ddy
Upvotes: 0
Reputation: 31
Problem solved.
After following the step in my post EDIT, I tried to run the make command on the makefile via the terminal. The program compiled fine, so I figured it was just the code analysis tool. I ended up going to Project>Properties>C/C++ General>Code Analysis>Launching and unselecting the run as you type and selecting the run with build option.
I'm assuming that this forces Eclipse to use the compiler output to create errors and warnings, rather than using some other built-in method. Maybe somebody can clarify that, though.
NOTE: I needed to restart eclipse before the steps took effect.
Many Thanks.
Upvotes: 1