2012-03-30 28 views
0

當我嘗試鏈接我的代碼時,出現鏈接錯誤(未定義的引用),我找不到原因。在鏈接過程中未定義對函數的引用

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中的「步驟(...)函數是不確定的。

所以...主()看起來像這樣的代碼(我離開斷包括,但它確實包括與步驟()函數,這是顯而易見的,因爲我沒有編譯錯誤)頭:

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()的調用根本沒有錯誤)。任何想法可能會導致這個問題?

+0

您是否100%確定步驟函數的標記與其標題及其實現之間是否匹配? – Mat 2012-03-30 15:24:07

+0

是的,我會在上面添加它,但是它被粘貼了很長時間。 – Kyle 2012-03-30 15:28:56

回答

1

看起來像你在你的定義中缺少&。檢查verlet_celllist

+0

哇......謝謝。我想我在粘貼之後改變了一些東西。很好 – Kyle 2012-03-30 15:54:43

相關問題