Eclipse 和 Gtkmm - “未定义的引用”

发布于 2024-12-21 03:56:03 字数 2231 浏览 2 评论 0原文

我使用 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++ 编译器杂项选项到其他标志中,并且与 Cross G++ 相同链接器标志中的编译器杂项选项。但这不起作用!

这是编译日志:

**** 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 它有效...

I use Eclipse and I wanted to use gtkmm in it. I have following code:

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

I added pkg-config --cflags --libs gtkmm-3.0 (with grave accents, of course) to Cross G++ Compiler Miscellanous options into Other flags and the same to the Cross G++ Compiler Miscellanous options into Linker flags. And it doesn't work!

Here's the compile log:

**** 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 ****

And I don't know why... When I compile it in terminal by: g++ -O0 -g3 -Wall -c -fmessage-length=0 'pkg-config --cflags --libs gtkmm-3.0' -o ./test ./main.cpp it works...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温折酒 2024-12-28 03:56:03

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

之前:${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${输出} ${INPUTS}

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

现在可以了。

I found a solution:
In Linker options, in Command line pattern I moved ${FLAGS} to the end, e.g.:

Before: ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

After: ${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}

And now it works.

み青杉依旧 2024-12-28 03:56:03

您必须在 pkg-config --cflags 中添加一个现在所在的位置(编译器选项),然后添加 pkg-config --libs > 链接器选项

You must divide to pkg-config --cflags <etc> an add there where it's now (compiler options) and then add pkg-config --libs <etc> to linker options

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文