C++ libstdc++:命令行中缺少 DSO

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33263288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:14:19  来源:igfitidea点击:

libstdc++: DSO missing from command line

c++makefilegtkmm

提问by wolx

I am having trouble implementing a gtkmm application's makefile. I have implemented a simple solution, however, I am getting the following error:

我在实现 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

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: 对符号“__gxx_personality_v0@@CXXABI_1.3”的未定义引用

/usr/lib/x86_64-linux-gnu/libstdc++.so.6:添加符号时出错:命令行中缺少DSO

collect2: 错误: ld 返回 1 个退出状态

:目标“主要”的配方失败

make: *** [main] 错误 1

Makefile:

生成文件:

# 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)

main.cpp:

主.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);
}

MainWindow.hpp:

主窗口.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

MainWindow.cpp:

主窗口.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
}

What am I doing wrong?

我究竟做错了什么?

回答by T? L?c Gia Hoàng

I met the same issue when built openCV libraries

我在构建 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

[SOLVE]

[解决]

For gcctry adding -lstdc++to your command.

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

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

For g++it will link libstdc.so.6++automatically

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

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

回答by Anil Patil

I had same problem it was solved by addiing -lstdc++ in command line.

我有同样的问题,它是通过在命令行中添加 -lstdc++ 来解决的。

回答by cce1911

I had a similar problem when compiling zeromq (zmq) into my project. Adding -lstdc++to the link line in my makefile solved the problem.

我在将 zeromq (zmq) 编译到我的项目中时遇到了类似的问题。将-lstdc++添加到我的 makefile 中的链接行解决了这个问题。