c++ - libstdc++ : DSO missing from command line

标签 c++ makefile gtkmm

我在执行 gtkmm 应用程序的 makefile 时遇到问题。我已经实现了一个简单的解决方案,但是,我收到以下错误:

g++ -Wall -std=c++11 pkg-config gtkmm-3.0 --cflags -c main.cpp

cc main.o pkg-config gtkmm-3.0 --libs -o main

/usr/bin/ld: main.o: undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'

/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

: recipe for target 'main' failed

make: *** [main] Error 1

生成文件:

# Compiler
CXX = g++
CXXFLAGS = -Wall -std=c++11 `pkg-config gtkmm-3.0 --cflags`

# gtkmm library flags
LDLIBS = `pkg-config gtkmm-3.0 --libs`

PROGRAM = main
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
DEPEND = .depend

.PHONY: clean

$(PROG): $(OBJS)
    $(CXX) $^ -o $@ $(LDLIBS)

# Object file rules:
.cpp.o:
    $(CXX) $(CXXFLAGS) -c $<

# Dependencies
.depend:
    rm -f ./.depend
    $(CXX) $(CXXFLAGS) -MM $(SRCS) > $(DEPEND)

all: .depend $(PROGRAM)

clean:
    rm -f $(OBJS)
    rm -f $(PROGRAM)
    rm -f $(DEPEND)

-include $(DEPEND)

主要.cpp:

#include <gtkmm/application.h>

#include "MainWindow.hpp"

int main(int argc, char *argv[]) {
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");

  MainWindow window;

  // Show windows and return when closed
  return app->run(window);
}

主窗口.hpp:

#ifndef GUI_MAIN_WINDOW_H
#define GUI_MAIN_WINDOW_H

#include <gtkmm.h>

class MainWindow: public Gtk::Window {

  public:
    MainWindow();
    virtual ~MainWindow();

  protected:
    Gtk::Frame frame;

};

#endif // GUI_MAIN_WINDOW_H

主窗口.cpp:

#include "MainWindow.hpp"

MainWindow::MainWindow() {
  // Set window properties
  set_title("Main window");
  set_size_request(300, 300);

  // Set window border width
  set_border_width(10);

  // Add frame
  add(frame);

  // Set frame's label
  frame.set_label("Frame");

  // Align the label at the right of the frame
  frame.set_label_align(Gtk::ALIGN_END, Gtk::ALIGN_START);

  // Set the style of the frame
  frame.set_shadow_type(Gtk::SHADOW_ETCHED_OUT);

  show_all_children();
}

MainWindow::~MainWindow() {
  // Nothing to do here
}

我做错了什么?

最佳答案

我在构建 openCV 库时遇到了同样的问题

$ gcc DisplayImage.cpp `pkg-config opencv --libs --cflags` -o DisplayImage
/usr/bin/ld: /tmp/ccbyJ7Ms.o: undefined reference to symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev@@GLIBCXX_3.4.21'
//usr/lib/i386-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

[解决]

对于 gcc,请尝试将 -lstdc++ 添加到您的命令中。

$ gcc DisplayImage.cpp `pkg-config opencv --libs --cflags` -o DisplayImage -lstdc++

对于g++,它会自动链接libstdc.so.6++

$ g++ DisplayImage.cpp `pkg-config opencv --libs --cflags` -o DisplayImage

关于c++ - libstdc++ : DSO missing from command line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33263288/

相关文章:

c++ - 如何设计可扩展的多重继承?

c++ - 维护 Makefile 和 CMakeLists.txt

c - 自动将您自己的代码插入到另一个项目中

c++ - 从 Window* 访问小部件

c++ - 没有匹配函数来调用‘Gtk::Main::run(window (&)())

c++ - 无法使用带有 g++ 的 -std 标志进行编译

c++ - 是否尝试修改 const_cast-ed,但动态分配的常量对象仍然是未定义的行为?

c++ - OpenMP 刷新与刷新(列表)

c++ - 将 3rd 方头文件放在源代码树中的什么位置?

c++ - Gtkmm 获取标签颜色