【问题标题】:Eclipse and Gtkmm - "undefined reference to"Eclipse 和 Gtkmm - “未定义的引用”
【发布时间】:2011-12-13 17:23:41
【问题描述】:

我使用 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 选项到 Other 标志中,并将 Cross G++ Compiler Miscellanous 选项添加到 Linker 标志中。而且它不起作用!

这是编译日志:

**** 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 它可以工作...

【问题讨论】:

    标签: c++ eclipse-cdt gtkmm


    【解决方案1】:

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

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

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

    现在它可以工作了。

    【讨论】:

    【解决方案2】:

    您必须划分到pkg-config --cflags &lt;etc&gt; 并添加到它现在所在的位置(编译器选项),然后将pkg-config --libs &lt;etc&gt; 添加到链接器选项

    【讨论】:

    • 你必须做错事,因为它必须运行。我已经做过很多次了,而且总是有效。
    • 好的,谢谢您的帮助。我找到了解决方案:我编辑了链接器命令行模式 - 我将 ${FLAGS} 移到了末尾。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2016-01-29
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多