我正在尝试编译一个多文件位的代码,到目前为止它一直运行良好。但现在我收到了一些链接器错误。我有一个类定义“njPhaseSpace”,报告为:
ld: duplicate symbol njPhaseSpace::njPhaseSpace(int)in Source/Currents.o and
/var/folders/p8/0bwv51kn2w5cx4jnsg6xm7340000gn/T//ccb0Psoz.o for architecture x86_64
我不知道 /var/folder/.../ccb0Psoz.o 文件是关于什么的,并且它不是(故意)开始在我的项目中使用的。如果我将名称更改为不同但相似的名称,例如 njPhaseSpaceX,它将很好地编译和链接。但是后来我使用'make clean'清理了项目,当我尝试重新制作时,我再次遇到相同的链接错误!(但使用不同的 /var/.../XXXXXX.o 文件)有什么建议吗?干杯
更新:更奇怪的事情:当我查看 /var/folder/... 目录以查看哪个文件导致重复时,不存在这样的文件!
更新: njPhaseSpace 源文件是:
// Standard header files
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <complex>
#include <iomanip>
#include "LoadBar.h"
// CLHEP header files
#include <CLHEP/Vector/LorentzVector.h>
#include <CLHEP/Random/RanluxEngine.h>
// More convenient label for four-vectors
typedef CLHEP::HepLorentzVector HLV;
// Definition of structure to hold the phase-space point
struct ParticleStruct {
HLV pa;
HLV pb;
HLV pep;
HLV pem;
HLV p1;
HLV p2;
HLV p3;
double xa;
double xb;
} ;
// A class for the n-jet phase space
class njPhaseSpace {
private:
// Incoming Particle Momenta
HLV pa;
HLV pb;
// Emitted leptons
HLV pep;
HLV pem;
// Outgoing parton momenta
std::vector <HLV> OutgoingPartons;
// Kinematic factors
double xa;
double xb;
public:
// Constructor for class
njPhaseSpace(int n);
// Returns a vector of the outgoing parton momenta
std::vector <HLV> ReturnOutgoingPartons() {
return OutgoingPartons;
}
// HLV IncomingForward
} ;
// Class constructor - adds n vectors to the Outgoing array
njPhaseSpace::njPhaseSpace(int n) {
// Add n final states to the OutgoingPartons vector
for (int i = 0; i < n; i++) {
HLV temp;
OutgoingPartons.push_back(temp);
}
}
更新:当类构造函数包含在类定义的主体中时,这个问题就消失了。虽然它很好,但我可以避免这种情况,但它并没有真正帮助,因为现在要开发我的课程,一切都必须放在定义内。
更新:用于编译的makefile(分析是单独的,我目前正在运行make Explorer -j8):
#/bin/bash
# CXX Compiler
CXX = g++
# Directories For Compilation
INCDIR = MadGraph
LIBDIR = MadGraph
SRCDIR = Source
# Compilation Flags
CXXFLAGS = -O3 -lm
LIBFLAGS = $(shell clhep-config --libs) $(shell fastjet-config --libs) $(shell clhep-config --libs) $(shell root-config --libs)
INCFLAGS = $(shell clhep-config --include) -I/$(INCDIR) -I$(SRCDIR) -I. $(shell fastjet-config --cxxflags --plugins) $(shell clhep-config --libs) $(shell root-config --cflags)
FLAGS = $(CXXFLAGS) $(LIBFLAGS) $(INCFLAGS)
# Object Files
Objects = $(addprefix $(SRCDIR)/, Currents.o mstwpdf.o LoadBar.o)
MadObjects = $(addprefix $(LIBDIR)/, HelAmps_sm.o Parameters_sm.o read_slha.o CPPProcess2j.o CPPProcess3j.o)
# Main targets
all: Analysis Explorer
Analysis: $(SRCDIR)/Analysis2jepem.cxx $(Objects) $(SRCDIR)/CGenerator2jepem.o
$(CXX) $(SRCDIR)/Analysis2jepem.cxx -o $@ $(FLAGS) $(Objects) $(SRCDIR)/CGenerator2jepem.o
Explorer: $(SRCDIR)/qQepemqQ_Explorer.cxx $(Objects) $(MadObjects) $(LIBDIR)/libmodel_sm.a
$(CXX) $(SRCDIR)/qQepemqQ_Explorer.cxx -o $@ $(FLAGS) $(Objects) -lmodel_sm -L$(LIBDIR)
# Build object files
$(Objects):
$(CXX) -c $(@:.o=.cxx) -o $@
# Build the MG5 object code
$(MadObjects):
$(CXX) -c $(@:.o=.cxx) -o $@ -I../
$(SRCDIR)/CGenerator2jepem.o:
$(CXX) -c $(@:.o=.cxx) -o $@
# Build the Standard Model library
$(LIBDIR)/libmodel_sm.a: $(MadObjects)
$(AR) cru $@ $^
ranlib $@
# Debugging flags
debug: CXX += -g -Wall -pendantic
debug: all
# Create a clean build
.PHONY: clean
clean:
rm -f $(Objects) $(MadObjects) $(LIBDIR)/2j/libmodel_sm.a $(LIBDIR)/3j/libmodel_sm.a $(TARGET) $(SRCDIR)/CGenerator2jepem.o Analysis Explorer