簡體   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