코드를 연결하려고 시도 할 때 링크 오류 (정의되지 않은 참조)가 발생하고 이유를 파악할 수 없습니다. 내가 오류가 나에게 말한다링크 중 함수에 대한 참조가 정의되지 않았습니다.
I am linking using the following command:
mpic++ -Wl,-V main.o Particle.o Particle_forces.o User_input.o output.o time_step_Gear_Verlet.o Verlet_variables.o -o DEM.exe -Lboost_mpi.a -Lboost_serialization.a
는 MAIN.CPP의 "단계 (...) 함수는.
정의되지 않은 그래서 ...) (주 이런 식으로 뭔가를 보이는위한 코드 (I 왼쪽 이 포함되어 있지만 내가 더 컴파일 오류)했다 없기 때문에 분명하다 단계() 함수와 헤더가 포함되어 있지 않습니다 떨어져 :
int main()
{
//do some stuff
for(int i=0;i<input_data.nstep();i++)
{
//call step() to do all calculations necessary for a particular timestep
step(particles, safe_particles, particle_properties, particle_forces, input_data, verlet_list, verlet_celllist, coll_eros_track, tan_contact_histories, collision_number_part);
//do some more stuff
}
return 0;
}
그리고 스텝 기능은 time_step_Gear_Verlet.cpp에서 찾을 수 있습니다
을void step(std::vector<Particle> & particles, std::vector<Particle> & safe_particles, std::vector<Particle_props> & particle_properties, std::vector<Particle_forces> & particle_forces, User_input& input_data, std::vector<std::set<int> > & verlet_list, vector<vector<vector<vector<int> > > > verlet_celllist, data_tracking & coll_eros_track, vector<map<int,Vector> > & tan_contact_histories, vector<int> & collision_number_part)
{
//define booleans used for checking what to do
//newverlet states whether the verlet lists are currently new and ok will be the output to make_verlet
bool ok=true, newverlet=false;
if(input_data.collisions_on())
{
//uses verlet_needs_update() to see if the verlet lists need to be updated
if(verlet_needs_update(particles, safe_particles, input_data))
{
//if the lists need to be updated then a call to make_verlet is made to make new lists and output is stored in "ok"
ok=make_verlet(particles, particle_properties, input_data, verlet_celllist, verlet_list);
//since new lists have been made, newverlet becomes true
newverlet=true;
}
//if something went wrong when the new lists were made, then a restoration has to be made
if(!ok)
{
cout<<"verlet list construction failed due to particles already touching. Try changing the verlet distance"<<endl;
exit(1);
}
//if the lists are new and make_verlet worked fine, then store current particle values
if (newverlet && ok)
{
//store current particle and time values
safe_particles=particles;
}
}
//call integrate() to integrate the equations of motion
integrate(particles, particle_properties, particle_forces, input_data, verlet_list, coll_eros_track, tan_contact_histories, collision_number_part);
}
헤더 정의 :
#ifndef time_step_Gear_h
#define time_step_Gear_h
#include <vector>
#include <map>
#include <set>
#include "Particle.h"
#include "Particle_props.h"
#include "Particle_forces.h"
#include "User_input.h"
#include "data_tracking.h"
void step(std::vector<Particle> &, std::vector<Particle> &, std::vector<Particle_props> &, std::vector<Particle_forces> &, User_input&, std::vector<std::set<int> > &, std::vector<std::vector<std::vector<std::vector<int> > > > &, data_tracking &, std::vector<std::map<int,Vector> > &, std::vector<int> &);
void make_forces(std::vector<Particle> &, std::vector<Particle_props> &, std::vector<Particle_forces> &, User_input&, std::vector<std::set<int> > &, data_tracking &, std::vector<std::map<int,Vector> > &, std::vector<int> &);
void integrate(std::vector<Particle> &, std::vector<Particle_props> &, std::vector<Particle_forces> &, User_input&, std::vector<std::set<int> > &, data_tracking &, std::vector<std::map<int,Vector> > &, std::vector<int> &);
void init_algorithm(std::vector<Particle> &, vector<Particle> & safe_particles, std::vector<Particle_props> &, User_input&, std::vector<std::vector<std::vector<std::vector<int> > > > &, std::vector<std::set<int> > &);
#endif
내가 분명히 함께 파일을 연결하고 (그리고 순서는 효과가 없습니다). main.cpp에서 호출되고 다른 .cpp 파일 내에서 정의 된 다른 함수와 함께이 문제가 발생하지 않습니다. (그리고 step() 호출을 주석 처리하면 오류가 전혀 발생하지 않습니다). 이 문제의 원인은 무엇입니까?
스텝 기능의 서명이 헤더와 구현 사이에서 일치합니까? – Mat
예, 위 내용을 추가하겠습니다. 그러나 너무 오래 되었기 때문에 복사 붙여 넣기를했습니다. – Kyle