File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
File.cpp.o: multiple definition of OpenPose flags CMakeFiles/.../main.cpp.o: first defined here
我已经多次发现这个问题,我在这里(在stackoverflow上(和其他地方(谷歌搜索(浏览了数十个找到的答案,但没有任何效果。起初,我将所有代码放在一个文件中,一切正常。但是现在,我需要将代码拆分为多个文件,创建一些类等等,所以我创建了以下文件:
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"
驱动程序关键点.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);
};
驱动程序关键点.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() {
}
主.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();
}
CMakeList.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
,但我在stdafx.h
中#pragma once
,所以问题在这里吗?
你能帮帮我吗?我在C/C++编程方面经验不足。谢谢。
我知道这很晚了,但我遇到了类似的问题,并且弹出了这个线程。
我的代码在一个文件中运行良好,然后在创建头文件并将其 #included 多个位置时,给了我与您类似的错误。就我而言,我的头文件中有 DEFINE_type(( 而不是 DECLARE_type((,这导致了问题,因为变量被多次定义。我会仔细检查您是否正在使用 DECLARE_ 方法而不是头文件中的 DEFINE_ 方法。
相关文章:
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- 在 main.cpp 的上下文中找不到目录(带有 CMake 的快板)
- 函数未在作用域中声明 / 如何结合使用 header.h、header.cpp 和 main.cpp?
- main.cpp(11):错误 C2059:语法错误:"字符串"
- 如何在 cpp 的 main() 中调用此函数
- 访问除main.cpp之外的.cpp文件中的QMLEngine/rootObject属性
- 生成main.c和main.cpp的单个Makefile
- C 函数未从 main.cpp C++ 调用
- 代码块始终在项目中运行 main.cpp
- 运行单独的 cpp 文件,每个文件都有 main()
- main.cpp 如何知道包含标头的源文件?
- 如何使用 c++ 从另一个 cpp 文件中的 main.cpp 调用实例化类
- 当我有多个类时,我应该以线性样式包含它们还是只包含在 main.cpp 中?
- 无法引用.cpp中的函数,以及 main 中的 .h 文件。C++
- main.cpp从 .h 文件调用公共虚拟方法
- main.cpp:(.text+0x8ea):在C++中未定义的引用
- \main.cpp|103|error: 与"operator<<"不匹配(操作数类型为"std::ostream {aka std::basic_ostream<char&g
- 实用程序函数不会在 .h 文件中初始化并在 main 中定义.cpp
- 编译php-cpp main.cpp文件时出错
- 多个文件的类用法 .h .cpp main.cpp