链接到外部对象文件时出现“多个定义”和“未定义引用”错误

时间:2019-11-29 07:11:23

标签: g++

我具有以下目录结构-

YCSB-C/
- db/
  - cceh_store.h (includes <src/CCEH.h>)
  - cceh_store.cc (includes cceh_store.h, <util/hash.h>)
  - cceh_store.o
  - Makefile (1 - builds cceh_store.o)
- ycsb.cc
- Makefile (2 - builds target 'ycsbc' from ycsb.cc by linking it with cceh_store.o)

CCEH/
- src/
  - CCEH.h (defines class CCEH)
  - CCEH_MSB.cc (implements CCEH methods, includes util/hash.h, util/persist.h)
  - CCEH_MSB.o
- util/
  - hash.h
  - persist.h
- Makefile (3 - builds CCEH_MSB.o)
  1. Makefile(3)首先运行以构建CCEH_MSB.o目标文件-

g++ -std=c++17 -I./ -lpthread -O3 -c -o src/CCEH_MSB.o src/CCEH_MSB.cpp -DINPLACE

  1. 然后运行Makefile(1)以构建cceh_store.o对象文件,该文件成功完成-

g++-8 -std=c++14 -c -g -Wall -pthread -I../ -I../../CCEH cceh_store.cc -o cceh_store.o

  1. 最后,当我运行Makefile(2)生成ycsbc-

g++ -std=c++11 -g -Wall -pthread -I./ -I../CCEH/ ycsbc.cc db/cceh_store.o ../CCEH/src/CCEH_MSB.o -o ycsbc

它失败并显示以下错误-

../CCEH/src/CCEH_MSB.o: In function `xxhash(void const*, unsigned long, unsigned long)':
CCEH_MSB.cpp:(.text+0x330): multiple definition of `xxhash(void const*, unsigned long, unsigned long)'
db/cceh_store.o:/home/osboxes/YCSB-C/db/../../CCEH/util/hash.h:236: first defined here

CCEH_MSB.cpp:(.text+0xdea): undefined reference to `kWriteLatencyInNS'

在这里,kWriteLatencyInNSCCEH/util/persist.h中定义

我已经花了几个小时,但是我无法弄清楚如何使ycsbc正确构建。我该如何解决?

0 个答案:

没有答案