gpt4 book ai didi

c++ - Eclipse 和 Gtkmm - "undefined reference to"

转载 作者:可可西里 更新时间:2023-11-01 17:35:44 24 4
gpt4 key购买 nike

我使用 Eclipse,我想在其中使用 gtkmm。我有以下代码:

#include <gtkmm.h>
#include <iostream>

int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);

Gtk::Window mainWindow;

Gtk::Button button("Click here");

mainWindow.set_title("Eclipse/GTKmm Demo");
mainWindow.set_border_width(4);
mainWindow.set_default_size(200, 50);

mainWindow.add(button);
button.show();

Gtk::Main::run(mainWindow);

return 0;
}

我将 pkg-config --cflags --libs gtkmm-3.0(当然带有重音)添加到 Cross G++ Compiler Miscellanous options into Other flags 和 Cross G++ Compiler Miscellanous链接器标志中的选项。而且它不起作用!

这是编译日志:

**** Build of configuration Debug for project User Directory Changer ****

make all
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 `pkg-config --cflags --libs gtkmm-3.0` -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: User Directory Changer
Invoking: Cross G++ Linker
g++ `pkg-config --cflags --libs gtkmm-3.0` -o "User Directory Changer" ./main.o
./main.o: In function `main':
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:12: undefined reference to `Gtk::Main::Main(int&, char**&, bool)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:14: undefined reference to `Gtk::Window::Window(Gtk::WindowType)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:16: undefined reference to `Glib::ustring::ustring(char const*)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:16: undefined reference to `Gtk::Button::Button(Glib::ustring const&, bool)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:16: undefined reference to `Glib::ustring::~ustring()'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:18: undefined reference to `Glib::ustring::ustring(char const*)'
[etc...]
collect2: ld returned 1 exit status
make: *** [User Directory Changer] Error 1

**** Build Finished ****

我不知道为什么...当我在终端编译它时:g++ -O0 -g3 -Wall -c -fmessage-length=0 'pkg-config --cflags --libs gtkmm -3.0' -o ./test ./main.cpp 它有效...

最佳答案

我找到了一个解决方案:在链接器选项中,在命令行模式中,我将 ${FLAGS} 移到了最后,例如:

之前:${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

之后:${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}

现在可以了。

关于c++ - Eclipse 和 Gtkmm - "undefined reference to",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8493403/

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