繁体   English   中英

链接阶段在 Ubuntu 上失败,但在 MacOS 上没有

[英]Linking stage fails on Ubuntu but not MacOS

我正在尝试使用 GStreamer C 库中的一些函数编译 C++ 程序。 在 MacOS Catelina 上使用 g++(随 homebrew 安装的 9.2 版)时,程序编译和链接得很好,但是在 Ubuntu 18.04 上使用 g++ 时,由于未定义的引用,它在链接阶段失败。 我没有在两个平台之间更改任何代码,代码非常简单,唯一使用的外部库是 GStreamer。

错误:

g++ `pkg-config --cflags --libs gstreamer-1.0` -std=gnu++11 -Wall -Wextra -c -o img_sys.o img_sys.cpp
g++ -std=gnu++11 -Wall -Wextra   -c -o img_cameras.o img_cameras.cpp
g++ `pkg-config --cflags --libs gstreamer-1.0` -std=gnu++11 -Wall -Wextra -c -o img_cameras_gstreamer.o img_cameras_gstreamer.cpp
g++ `pkg-config --cflags --libs gstreamer-1.0` -std=gnu++11 -Wall -Wextra -o img_sys img_sys.o img_cameras.o img_cameras_gstreamer.o
img_cameras_gstreamer.o: In function `gst_caps_unref':
img_cameras_gstreamer.cpp:(.text+0x14): undefined reference to `gst_mini_object_unref'
img_cameras_gstreamer.o: In function `ImgSys::GStreamerCameras::msgReceivedCallback(_GstBus*, _GstMessage*, void*)':
img_cameras_gstreamer.cpp:(.text+0x75): undefined reference to `gst_message_get_structure'
img_cameras_gstreamer.cpp:(.text+0xa3): undefined reference to `gst_structure_get'
img_cameras_gstreamer.cpp:(.text+0x109): undefined reference to `gst_message_parse_error'
img_cameras_gstreamer.cpp:(.text+0x125): undefined reference to `g_print'
...
collect2: error: ld returned 1 exit status
makefile:10: recipe for target 'img_sys' failed
make: *** [img_sys] Error 1

生成文件:

CXX = g++
CXXFLAGS = -std=gnu++11 -Wall -Wextra
GSTREAMER = `pkg-config --cflags --libs gstreamer-1.0`

img_sys: img_sys.o img_cameras.o img_cameras_gstreamer.o
    $(CXX) $(GSTREAMER) $(CXXFLAGS) -o $@ $^

img_sys.o: img_sys.cpp
    $(CXX) $(GSTREAMER) $(CXXFLAGS) -c -o $@ $^
img_cameras.o: img_sys.hpp
img_cameras_gstreamer.o: img_cameras_gstreamer.cpp
    $(CXX) $(GSTREAMER) $(CXXFLAGS) -c -o $@ $^

img_cameras_gstreamer.cpp 包括:

#include <iostream>
#include <string>
#include <vector>
#include <gst/gst.h>
#include "img_sys.hpp"
#include "img_cameras_gstreamer.hpp"

img_cameras_gstreamer.hpp:

#ifndef IMG_CAMERAS_GSTREAMER_GUARD_H
#define IMG_CAMERAS_GSTREAMER_GUARD_H

#include <gst/gst.h>
#include "img_sys.hpp"

namespace ImgSys {
    class GStreamerCameras: public ImgSys::Cameras {
    private:
        GstElement *pipeline;
        GMainLoop *loop;
        guint bus_watch_id;
        static gboolean msgReceivedCallback(__attribute__((unused)) GstBus*, GstMessage*, gpointer);
        static gboolean pipelineTimeOut(__attribute__((unused)) gpointer);
    public:
        void build();
        void beginCapture();
    };
}

#endif

对不起所有的代码,希望尽可能地解释。

我在这里找到了问题的答案: https : //stackoverflow.com/a/8359200/4638141

事实证明,较新版本的 Ubuntu 的 gcc 需要像这样的不同顺序的 pkg-config 选项(取自链接的帖子):

gcc `pkg-config gstreamer-0.10 --cflags` main.c -o player.out `pkg-config gstreamer-0.10 --libs`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM