Файл. cpp .o: множественное определение флагов OpenPose. CMakeFiles /.../ main. cpp .o: сначала определено здесь - PullRequest
0 голосов
/ 08 февраля 2020

Я обнаружил эту проблему много раз, и я просмотрел десятки найденных ответов здесь (в stackoverflow) и в других местах (поиск в Google), но ничего не помогло. Сначала у меня был весь код в одном файле, и все работало правильно. Но теперь мне нужно было разбить код на несколько файлов, создать несколько классов и так далее, поэтому я создал следующие файлы:

stdafx.h

#pragma once

#include <iostream>
#include <fstream>
#include <iomanip>
#include <ctime>

// opencv
#include <opencv2/opencv.hpp>

// openpose
#include <openpose/flags.hpp>
#include <openpose/headers.hpp>

#include "driver-keypoints.h"

driver-keypoints.h

#pragma once

class DriverKeypoints
{
public:
    DriverKeypoints();

    static const int NOSE = 0;
    static const int NECK = 1;
    static const int R_SHOULDER = 2;
    static const int R_ELBOW = 3;
    static const int R_WRIST = 4;
    static const int L_SHOULDER = 5;
    static const int L_ELBOW = 6;
    static const int L_WRIST = 7;
    static const int MID_HIP = 8;
    static const int R_HIP = 9;
    static const int L_HIP = 12;

    int get_video_keypoints();

protected:
    void save_keypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>>& datums_ptr,
                        std::string out_file, bool is_first);
    void configure_wrapper(op::Wrapper& op_wrapper);
};

driver-keypoints. cpp

#include "stdafx.h"

// Custom OpenPose flags
// TODO: here should not have been an absolute path
DEFINE_string(output_path, "/path/to/output/openpose/", "Path to save required keypoints.");
DEFINE_bool(no_display, false, "Enable to disable the visual display.");

void DriverKeypoints::save_keypoints(const std::shared_ptr<std::vector<std::shared_ptr<op::Datum>>> &datums_ptr,
                                     std::string out_file, bool is_first) {
}

void DriverKeypoints::configure_wrapper(op::Wrapper &op_wrapper) {
}

int DriverKeypoints::get_video_keypoints() {
}

main . cpp

#include "stdafx.h"

int main(int argc, char** argv) {
  FLAGS_disable_multi_thread = true;

  FLAGS_net_resolution = "-1x192";
  FLAGS_number_people_max = 0;

  // Parsing command line flags
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  // run parse keypoints from video
  DriverKeypoints driver_keypoints;
  return driver_keypoints.get_video_keypoints();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
project(my_project)

set(CMAKE_CXX_STANDARD 14)


find_package(OpenCV REQUIRED)
find_package(CUDA REQUIRED)
find_package(Caffe REQUIRED)
find_package(gflags REQUIRED)


include_directories(
        OpenCV_INCLUDE_DIRS
        ${CUDA_INCLUDE_DIRS}
        ${CAFFE_INCLUDE_DIRS}
)

# TODO: here should not have been an absolute path
include(/home/path_to_openpose/openpose/cmake/Utils.cmake)

set(SOURCE_FILES main.cpp driver-keypoints.cpp)
add_executable(anomalies_analysis ${SOURCE_FILES})

target_link_libraries(
        anomalies_analysis
        ${OpenCV_LIBS}
        ${CUDA_LIBRARIES}
        openpose
        gflags
)

И я получаю следующие ошибки :

CMakeFiles/anomalies_analysis.dir/driver-keypoints.cpp.o:(.data+0x0): multiple definition of `fLI::FLAGS_logging_level'
CMakeFiles/anomalies_analysis.dir/main.cpp.o:(.data+0x0): first defined here
CMakeFiles/anomalies_analysis.dir/driver-keypoints.cpp.o:(.data+0x4): multiple definition of `fLI::FLAGS_nologging_level'
CMakeFiles/anomalies_analysis.dir/main.cpp.o:(.data+0x4): first defined here
CMakeFiles/anomalies_analysis.dir/driver-keypoints.cpp.o:(.bss+0x0): multiple definition of `fLB::FLAGS_disable_multi_thread'
CMakeFiles/anomalies_analysis.dir/main.cpp.o:(.bss+0x0): first defined here
CMakeFiles/anomalies_analysis.dir/driver-keypoints.cpp.o:(.bss+0x1): multiple definition of `fLB::FLAGS_nodisable_multi_thread'
CMakeFiles/anomalies_analysis.dir/main.cpp.o:(.bss+0x1): first defined here
...

Существует много ответов типа:

  • Вы должны объявить что-то как встроенное (но это невозможно)
  • Вы должны определить что-то только один раз (но я кажется, я делаю это, похоже, проблема в том, что в том числе openpose/flags.hpp, но у меня есть #pragma once в stdafx.h, так что проблема здесь?)

Не могли бы вы помочь мне ? Я недостаточно опытен в программировании на C / C ++. Большое спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...