gpt4 book ai didi

c++ - 配置 Eclipse CDT 以使用 wxWidgets

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:24:02 24 4
gpt4 key购买 nike

我一直在尝试配置 Eclipse CDT(在 Ubuntu Precise 上)以使用 wxWidgets 编译程序。我在使用 Eclipse 时收到错误,但该程序使用我提供的 makefile 编译得很好。我已按照 http://wiki.wxwidgets.org/Eclipse#Linux 中给出的说明进行操作,但仍然没有成功。 (即,我相信我已经正确设置了编译器和链接器标志。)

我的头文件如下:

#ifndef READIMAGE_H_
#define READIMAGE_H_

class Image{
wxImage *loadedImage;
public:
Image(string filename);
void loadImage(string filename){};
};

#endif /* READIMAGE_H_ */

我的源文件如下:

#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");
}

我收到的错误是:

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()'

如果这有帮助,makefile 如下:

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)

# ------------------

有什么想法吗?

非常感谢。

编辑

在 C++ 编译器和链接器的命令行模式中(分别为项目>属性>GCC C++ 编译器和>GCC C++ 链接器),如果我将 ${FLAGS} 移动到模式的末尾,那么我只会收到一个错误:

Type 'wxImage' could not be resolved

注意我没有收到任何包含的警告,提示编译器和链接器可以找到这些库。

最佳答案

问题已解决。

按照我的帖子 EDIT 中的步骤操作后,我尝试通过终端在 makefile 上运行 make 命令。该程序编译正常,所以我认为它只是代码分析工具。我最终转到 Project>Properties>C/C++ General>Code Analysis>Launching 并取消选择 run as you type 并选择 run with build 选项。

我假设这会强制 Eclipse 使用编译器输出来创建错误和警告,而不是使用其他一些内置方法。不过,也许有人可以澄清这一点。

注意:在这些步骤生效之前我需要重启eclipse。

非常感谢。

关于c++ - 配置 Eclipse CDT 以使用 wxWidgets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21865741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com