我在clion
中使用osx
来使用clang
编译我的c ++项目,但它抱怨duplicate symbol for architecture x86_64
,这是详细消息:
duplicate symbol __ZN4Util16axisAngle2rotMatERKN5Eigen6MatrixIdLi3ELi1ELi0ELi3ELi1EEEf in:
CMakeFiles/ahrs.dir/src/algs.cpp.o
CMakeFiles/ahrs.dir/src/AHRS.cpp.o
ld: 1 duplicate symbol for architecture x86_64
我搜索了一段时间,似乎我可能以错误的方式链接头文件,但我查看了我的cpp,我认为我没有做错事。
algs.cpp:
#include <algs.h>
#include <Util.h>
#include <AHRS.h>
AHRS.cpp:
#include <AHRS.h>
#include <Util.h>
algs.h:
#ifndef AHRS_ALGS_H
#define AHRS_ALGS_H
#include <Dense>
using namespace Eigen;
class algs {
private:
VectorXi stationary;
public:
VectorXd filter(MatrixX3d& acc);
void gradient_descent(MatrixX3d acc, MatrixX3d gyo, VectorXi time);
};
#endif //AHRS_ALGS_H
Util.h:
#ifndef AHRS_UTIL_H
#define AHRS_UTIL_H
#include <math.h>
#include <Dense>
#include <src/Geometry/Quaternion.h>
#include <vector>
using namespace Eigen;
namespace Util {
//many inline functions in this namespace.
...
}
#endif //AHRS_UTIL_H
AHRS.h:
#ifndef AHRS_AHRS_H
#define AHRS_AHRS_H
#include <Dense>
using namespace Eigen;
class AHRS {
private:
Quaterniond q;
Vector3d int_error;
int kp_ramped;
public:
double kp;
int ki;
int kp_init;
int init_period;
double sample_period;
Quaterniond quaternion;
AHRS();
void reset();
};
#endif //AHRS_AHRS_H
和CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(AHRS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_subdirectory(test)
include_directories(Eigen)
include_directories(include)
set(AHRS_HEAD include/)
set(AHRS_SRC src/main.cpp src/Biquad.cpp src/filtfilt.cpp src/Butterworth.cpp src/algs.cpp src/AHRS.cpp)
add_executable(ahrs ${AHRS_SRC} ${AHRS_HEAD})
我的所有头文件都在include
文件夹中。我该如何解决这个问题?